Use remove_and_dispose_if where applicable

This commit is contained in:
Thomas Goyne 2012-11-28 08:17:59 -08:00
parent 6ab8345148
commit 174a992974
2 changed files with 11 additions and 23 deletions

View file

@ -517,12 +517,9 @@ static void delete_lines(agi::Context *c, wxString const& commit_message) {
}
// Delete selected lines
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ) {
if (sel.count(static_cast<AssDialogue*>(&*it)))
delete &*it++;
else
++it;
}
c->ass->Line.remove_and_dispose_if([&sel](AssEntry const& e) {
return sel.count(const_cast<AssDialogue *>(static_cast<const AssDialogue*>(&e)));
}, [](AssEntry *e) { delete e; });
// If we didn't get a new active line then we just deleted all the dialogue
// lines, so make a new one

View file

@ -182,24 +182,16 @@ void SubtitleFormat::ConvertNewlines(AssFile &file, wxString const& newline, boo
}
void SubtitleFormat::StripComments(AssFile &file) {
for (entryIter it = file.Line.begin(); it != file.Line.end(); ) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it);
if (!diag || (!diag->Comment && diag->Text.size()))
++it;
else {
delete &*it++;
}
}
file.Line.remove_and_dispose_if([](AssEntry const& e) {
const AssDialogue *diag = dynamic_cast<const AssDialogue*>(&e);
return diag && (diag->Comment || !diag->Text);
}, [](AssEntry *e) { delete e; });
}
void SubtitleFormat::StripNonDialogue(AssFile &file) {
for (entryIter it = file.Line.begin(); it != file.Line.end(); ) {
if (dynamic_cast<AssDialogue*>(&*it))
++it;
else {
delete &*it++;
}
}
file.Line.remove_and_dispose_if([](AssEntry const& e) {
return e.Group() != ENTRY_DIALOGUE;
}, [](AssEntry *e) { delete e; });
}
static bool dialog_start_lt(AssEntry &pos, AssDialogue *to_insert) {
@ -318,8 +310,7 @@ void SubtitleFormat::LoadFormats() {
}
void SubtitleFormat::DestroyFormats() {
for (auto it = formats.begin(); it != formats.end(); )
delete *it++;
delete_clear(formats);
}
template<class Cont, class Pred>