Handle the case of inserting a dialogue line into a file containing no dialogue lines in Auto4 Lua. Fixes #1363.

(The sample attached to the ticket still produces an invalid file because of poor logic in the Lua script, it chooses to place its configuration right before the first blank line in the file, but in the "original.ass" file, the first blank line is before [Script Info].)

Originally committed to SVN as r5982.
This commit is contained in:
Niels Martin Hansen 2011-12-06 21:25:51 +00:00
parent a42e8277b4
commit 26a8a64ef3
1 changed files with 12 additions and 3 deletions

View File

@ -706,9 +706,18 @@ namespace Automation4 {
if (e->GetType() == ENTRY_DIALOGUE) {
// find insertion point, looking backwards
std::list<AssEntry*>::iterator it = laf->ass->Line.end();
do { --it; } while ((*it)->GetType() != ENTRY_DIALOGUE);
// found last dialogue entry in file, move one past
++it;
do {
--it;
} while (it != laf->ass->Line.begin() && (*it)->GetType() != ENTRY_DIALOGUE);
if (it != laf->ass->Line.begin()) {
// found last dialogue entry in file, move one past
++it;
}
else {
// no dialogue entries in the file, insert at the end
// (see bug #1363)
it = laf->ass->Line.end();
}
laf->ass->Line.insert(it, e);
}
else {