* Fix bug in SRT parsing: In some cases a blank line too much is counted.

* Make SRT no longer coalesce line breaks, Aegisub will now write SRT files with blank lines in subtitles.
Updates #1213.

Originally committed to SVN as r4558.
This commit is contained in:
Niels Martin Hansen 2010-06-20 19:42:13 +00:00
parent 2fc8420ee9
commit e5eb91a269
3 changed files with 10 additions and 6 deletions

View file

@ -417,7 +417,7 @@ void SubtitleFormat::SortLines() {
/// @param format /// @param format
/// @param lineEnd /// @param lineEnd
/// ///
void SubtitleFormat::ConvertTags(int format,wxString lineEnd) { void SubtitleFormat::ConvertTags(int format,const wxString &lineEnd,bool mergeLineBreaks) {
using std::list; using std::list;
list<AssEntry*>::iterator next; list<AssEntry*>::iterator next;
for (list<AssEntry*>::iterator cur=Line->begin();cur!=Line->end();cur++) { for (list<AssEntry*>::iterator cur=Line->begin();cur!=Line->end();cur++) {
@ -431,7 +431,9 @@ void SubtitleFormat::ConvertTags(int format,wxString lineEnd) {
current->Text.Replace(_T("\\h"),_T(" "),true); current->Text.Replace(_T("\\h"),_T(" "),true);
current->Text.Replace(_T("\\n"),lineEnd,true); current->Text.Replace(_T("\\n"),lineEnd,true);
current->Text.Replace(_T("\\N"),lineEnd,true); current->Text.Replace(_T("\\N"),lineEnd,true);
while (current->Text.Replace(lineEnd+lineEnd,lineEnd,true)) {}; if (mergeLineBreaks) {
while (current->Text.Replace(lineEnd+lineEnd,lineEnd,true)) {};
}
} }
} }
} }

View file

@ -103,7 +103,7 @@ protected:
void CreateCopy(); void CreateCopy();
void ClearCopy(); void ClearCopy();
void SortLines(); void SortLines();
void ConvertTags(int format,wxString lineEnd); void ConvertTags(int format,const wxString &lineEnd,bool mergeLineBreaks=true);
//void Merge(bool identical,bool overlaps,bool stripComments,bool stripNonDialogue); //void Merge(bool identical,bool overlaps,bool stripComments,bool stripNonDialogue);
void StripComments(); void StripComments();
void StripNonDialogue(); void StripNonDialogue();

View file

@ -184,7 +184,8 @@ found_timestamps:
if (text_line.IsEmpty()) { if (text_line.IsEmpty()) {
// that's not very interesting... blank subtitle? // that's not very interesting... blank subtitle?
state = 5; state = 5;
linebreak_debt = 1; // no previous line that needs a line break after
linebreak_debt = 0;
break; break;
} }
line->Text.Append(text_line); line->Text.Append(text_line);
@ -197,6 +198,7 @@ found_timestamps:
if (text_line.IsEmpty()) { if (text_line.IsEmpty()) {
// blank line, next may begin a new subtitle // blank line, next may begin a new subtitle
state = 5; state = 5;
// previous line needs a line break after
linebreak_debt = 1; linebreak_debt = 1;
break; break;
} }
@ -262,12 +264,12 @@ void SRTSubtitleFormat::WriteFile(wxString _filename,wxString encoding) {
StripComments(); StripComments();
// Tags must be converted in two passes // Tags must be converted in two passes
// First ASS style overrides are converted to SRT but linebreaks are kept // First ASS style overrides are converted to SRT but linebreaks are kept
ConvertTags(2,_T("\\N")); ConvertTags(2,_T("\\N"),false);
// Then we can recombine overlaps, this requires ASS style linebreaks // Then we can recombine overlaps, this requires ASS style linebreaks
RecombineOverlaps(); RecombineOverlaps();
MergeIdentical(); MergeIdentical();
// And finally convert linebreaks // And finally convert linebreaks
ConvertTags(0,_T("\r\n")); ConvertTags(0,_T("\r\n"),false);
// Otherwise unclosed overrides might affect lines they shouldn't, see bug #809 for example // Otherwise unclosed overrides might affect lines they shouldn't, see bug #809 for example
// Write lines // Write lines