From 8f8952293bb1cdcc80a8bcb48ece162c71d8cd37 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 13 Mar 2006 22:25:09 +0000 Subject: [PATCH] Fixed bug which caused extra newlines to be added at the end of file. Originally committed to SVN as r221. --- core/changelog.txt | 1 + core/subtitle_format_ass.cpp | 15 ++++++++++++--- core/text_file_writer.cpp | 4 ++-- core/text_file_writer.h | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/core/changelog.txt b/core/changelog.txt index 93d287525..7613529b0 100644 --- a/core/changelog.txt +++ b/core/changelog.txt @@ -66,6 +66,7 @@ Please visit http://aegisub.net to download latest version - Removed video frame/subtitles time sync controls from the grid context menu. (AMZ) - Timeline is now drawn below audio display. (AMZ) - Dragging the timeline will now scroll audio display. (AMZ) +- Fixed bug which caused extra newlines to be added at the end of file. (AMZ) = 1.09 beta - 2006.01.16 =========================== diff --git a/core/subtitle_format_ass.cpp b/core/subtitle_format_ass.cpp index 6a1e1223c..846b415f5 100644 --- a/core/subtitle_format_ass.cpp +++ b/core/subtitle_format_ass.cpp @@ -110,8 +110,17 @@ void ASSSubtitleFormat::WriteFile(wxString _filename,wxString encoding) { // Write lines using std::list; - for (list::iterator cur=Line->begin();cur!=Line->end();cur++) { - if (ssa) file.WriteLineToFile((*cur)->GetSSAText()); - else file.WriteLineToFile((*cur)->GetEntryData()); + AssEntry *entry; + for (list::iterator cur=Line->begin();cur!=Line->end();) { + // Get entry + entry = *cur; + + // Only add a line break if there is a next line + cur++; + bool lineBreak = cur != Line->end(); + + // Write line + if (ssa) file.WriteLineToFile(entry->GetSSAText(),lineBreak); + else file.WriteLineToFile(entry->GetEntryData(),lineBreak); } } diff --git a/core/text_file_writer.cpp b/core/text_file_writer.cpp index c910ffe18..ec87508a3 100644 --- a/core/text_file_writer.cpp +++ b/core/text_file_writer.cpp @@ -101,13 +101,13 @@ void TextFileWriter::Close() { ///////////////// // Write to file -void TextFileWriter::WriteLineToFile(wxString line) { +void TextFileWriter::WriteLineToFile(wxString line,bool addLineBreak) { // Make sure it's loaded if (!open) Open(); // Add line break wxString temp = line; - temp += _T("\r\n"); + if (addLineBreak) temp += _T("\r\n"); // Add BOM if it's the first line and the target format is Unicode if (IsFirst && IsUnicode) { diff --git a/core/text_file_writer.h b/core/text_file_writer.h index d873b64c0..bd6451e1e 100644 --- a/core/text_file_writer.h +++ b/core/text_file_writer.h @@ -65,7 +65,7 @@ public: TextFileWriter(wxString filename,wxString encoding=_T("")); ~TextFileWriter(); - void WriteLineToFile(wxString line); + void WriteLineToFile(wxString line,bool addLineBreak=true); };