diff --git a/aegisub/src/command/edit.cpp b/aegisub/src/command/edit.cpp index 3470abfbe..37a2b490b 100644 --- a/aegisub/src/command/edit.cpp +++ b/aegisub/src/command/edit.cpp @@ -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(&*it))) - delete &*it++; - else - ++it; - } + c->ass->Line.remove_and_dispose_if([&sel](AssEntry const& e) { + return sel.count(const_cast(static_cast(&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 diff --git a/aegisub/src/subtitle_format.cpp b/aegisub/src/subtitle_format.cpp index a22fdd7ab..df4db5c9e 100644 --- a/aegisub/src/subtitle_format.cpp +++ b/aegisub/src/subtitle_format.cpp @@ -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(&*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(&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(&*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