From 67df64e8795f1fab4cc2eabd62b8219f16bc4390 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 3 Nov 2012 20:53:03 -0700 Subject: [PATCH] Use range-based for loops in a bunch of places --- aegisub/src/ass_dialogue.cpp | 35 ++++---- aegisub/src/ass_export_filter.cpp | 6 +- aegisub/src/ass_exporter.cpp | 20 ++--- aegisub/src/ass_file.cpp | 41 +++++----- aegisub/src/ass_karaoke.cpp | 37 ++++----- aegisub/src/ass_override.cpp | 89 ++++++++++----------- aegisub/src/ass_parser.cpp | 4 +- aegisub/src/ass_style_storage.cpp | 14 ++-- aegisub/src/audio_display.cpp | 15 ++-- aegisub/src/audio_karaoke.cpp | 4 +- aegisub/src/audio_marker.cpp | 5 +- aegisub/src/audio_player.cpp | 6 +- aegisub/src/audio_timing_dialogue.cpp | 38 +++++---- aegisub/src/audio_timing_karaoke.cpp | 10 +-- aegisub/src/auto4_base.cpp | 21 +++-- aegisub/src/auto4_lua.cpp | 15 ++-- aegisub/src/auto4_lua_assfile.cpp | 10 +-- aegisub/src/auto4_lua_dialog.cpp | 25 +++--- aegisub/src/base_grid.cpp | 17 ++-- aegisub/src/block_cache.h | 13 ++- aegisub/src/charset_detect.cpp | 38 +++++---- aegisub/src/command/audio.cpp | 6 +- aegisub/src/command/command.cpp | 9 +-- aegisub/src/command/edit.cpp | 8 +- aegisub/src/command/time.cpp | 29 +++---- aegisub/src/dialog_attachments.cpp | 5 +- aegisub/src/dialog_automation.cpp | 8 +- aegisub/src/dialog_colorpicker.cpp | 2 +- aegisub/src/dialog_fonts_collector.cpp | 16 ++-- aegisub/src/dialog_kara_timing_copy.cpp | 27 +++---- aegisub/src/dialog_manager.h | 6 +- aegisub/src/dialog_properties.cpp | 4 +- aegisub/src/dialog_resample.cpp | 6 +- aegisub/src/dialog_search_replace.cpp | 4 +- aegisub/src/dialog_selection.cpp | 4 +- aegisub/src/dialog_shift_times.cpp | 8 +- aegisub/src/dialog_spellchecker.cpp | 6 +- aegisub/src/dialog_style_editor.cpp | 10 +-- aegisub/src/dialog_style_manager.cpp | 34 ++++---- aegisub/src/dialog_translation.cpp | 5 +- aegisub/src/export_fixstyle.cpp | 7 +- aegisub/src/export_framerate.cpp | 31 ++++--- aegisub/src/factory_manager.h | 13 ++- aegisub/src/ffmpegsource_common.cpp | 6 +- aegisub/src/font_file_lister.cpp | 23 +++--- aegisub/src/font_file_lister_fontconfig.cpp | 6 +- aegisub/src/frame_main.cpp | 3 +- aegisub/src/gl_text.cpp | 18 +---- aegisub/src/hotkey.cpp | 6 +- aegisub/src/hotkey_data_view_model.cpp | 37 +++++---- aegisub/src/main.cpp | 12 +-- aegisub/src/menu.cpp | 20 ++--- aegisub/src/mkv_wrap.cpp | 4 +- aegisub/src/preferences.cpp | 23 +++--- aegisub/src/scintilla_text_ctrl.cpp | 8 +- aegisub/src/spellchecker.cpp | 10 +-- aegisub/src/subs_edit_box.cpp | 8 +- aegisub/src/subs_edit_ctrl.cpp | 30 ++++--- aegisub/src/subtitle_format.cpp | 24 +++--- aegisub/src/subtitle_format_ass.cpp | 8 +- aegisub/src/subtitle_format_ebu3264.cpp | 88 ++++++++++---------- aegisub/src/subtitle_format_encore.cpp | 4 +- aegisub/src/subtitle_format_microdvd.cpp | 4 +- aegisub/src/subtitle_format_srt.cpp | 37 +++++---- aegisub/src/subtitle_format_transtation.cpp | 4 +- aegisub/src/subtitle_format_ttxt.cpp | 10 +-- aegisub/src/subtitle_format_txt.cpp | 15 ++-- aegisub/src/subtitles_provider.cpp | 20 ++--- aegisub/src/thesaurus.cpp | 4 +- aegisub/src/threaded_frame_source.cpp | 4 +- aegisub/src/toolbar.cpp | 4 +- aegisub/src/utils.cpp | 10 +-- aegisub/src/video_out_gl.cpp | 4 +- aegisub/src/video_provider_cache.cpp | 2 +- aegisub/src/video_provider_manager.cpp | 14 ++-- aegisub/src/video_slider.cpp | 4 +- aegisub/src/visual_tool.cpp | 14 ++-- aegisub/src/visual_tool_clip.cpp | 7 +- aegisub/src/visual_tool_cross.cpp | 15 ++-- aegisub/src/visual_tool_drag.cpp | 31 ++++--- aegisub/src/visual_tool_vector_clip.cpp | 15 ++-- 81 files changed, 585 insertions(+), 682 deletions(-) diff --git a/aegisub/src/ass_dialogue.cpp b/aegisub/src/ass_dialogue.cpp index dc6502299..dc397e7b5 100644 --- a/aegisub/src/ass_dialogue.cpp +++ b/aegisub/src/ass_dialogue.cpp @@ -235,10 +235,9 @@ std::vector AssDialogue::ParseTags() const { Blocks.push_back(block); // Look for \p in block - std::vector::iterator curTag; - for (curTag = block->Tags.begin(); curTag != block->Tags.end(); ++curTag) { - if ((*curTag)->Name == "\\p") { - drawingLevel = (*curTag)->Params[0]->Get(0); + for (auto tag : block->Tags) { + if (tag->Name == "\\p") { + drawingLevel = tag->Params[0]->Get(0); } } } @@ -284,17 +283,17 @@ void AssDialogue::StripTag (wxString tagName) { wxString final; // Look for blocks - for (std::vector::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) { - if ((*cur)->GetType() != BLOCK_OVERRIDE) { - final += (*cur)->GetText(); + for (auto block : Blocks) { + if (block->GetType() != BLOCK_OVERRIDE) { + final += block->GetText(); continue; } - AssDialogueBlockOverride *over = static_cast(*cur); + AssDialogueBlockOverride *over = static_cast(block); wxString temp; - for (size_t i = 0; i < over->Tags.size(); ++i) { - if (over->Tags[i]->Name != tagName) - temp += *over->Tags[i]; + for (auto tag : over->Tags) { + if (tag->Name != tagName) + temp += *tag; } if (!temp.empty()) @@ -308,13 +307,13 @@ void AssDialogue::StripTag (wxString tagName) { void AssDialogue::UpdateText () { if (Blocks.empty()) return; Text.clear(); - for (std::vector::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) { - if ((*cur)->GetType() == BLOCK_OVERRIDE) { + for (auto block : Blocks) { + if (block->GetType() == BLOCK_OVERRIDE) { Text += "{"; - Text += (*cur)->GetText(); + Text += block->GetText(); Text += "}"; } - else Text += (*cur)->GetText(); + else Text += block->GetText(); } } @@ -345,9 +344,9 @@ wxString AssDialogue::GetMarginString(int which, bool pad) const { void AssDialogue::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) { // Apply for all override blocks - for (std::vector::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) { - if ((*cur)->GetType() == BLOCK_OVERRIDE) { - static_cast(*cur)->ProcessParameters(callback, userData); + for (auto block : Blocks) { + if (block->GetType() == BLOCK_OVERRIDE) { + static_cast(block)->ProcessParameters(callback, userData); } } } diff --git a/aegisub/src/ass_export_filter.cpp b/aegisub/src/ass_export_filter.cpp index d32769fb1..cf1afc5b5 100644 --- a/aegisub/src/ass_export_filter.cpp +++ b/aegisub/src/ass_export_filter.cpp @@ -89,9 +89,9 @@ void AssExportFilterChain::Clear() { } AssExportFilter *AssExportFilterChain::GetFilter(wxString const& name) { - for (FilterList::iterator it = filters()->begin(); it != filters()->end(); ++it) { - if ((*it)->name == name) - return *it; + for (auto filter : *filters()) { + if (filter->name == name) + return filter; } return 0; } diff --git a/aegisub/src/ass_exporter.cpp b/aegisub/src/ass_exporter.cpp index e4832a36a..f6ebe52cc 100644 --- a/aegisub/src/ass_exporter.cpp +++ b/aegisub/src/ass_exporter.cpp @@ -64,16 +64,16 @@ AssExporter::~AssExporter () { void AssExporter::DrawSettings(wxWindow *parent, wxSizer *target_sizer) { is_default = false; - for (filter_iterator cur = filter_list_begin(); cur != filter_list_end(); ++cur) { + for (auto filter : *AssExportFilterChain::GetFilterList()) { // Make sure to construct static box sizer first, so it won't overlap // the controls on wxMac. - wxSizer *box = new wxStaticBoxSizer(wxVERTICAL, parent, (*cur)->GetName()); - wxWindow *window = (*cur)->GetConfigDialogWindow(parent, c); + wxSizer *box = new wxStaticBoxSizer(wxVERTICAL, parent, filter->GetName()); + wxWindow *window = filter->GetConfigDialogWindow(parent, c); if (window) { box->Add(window, 0, wxEXPAND, 0); target_sizer->Add(box, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); target_sizer->Show(box, false); - Sizers[(*cur)->GetName()] = box; + Sizers[filter->GetName()] = box; } else { delete box; @@ -90,9 +90,9 @@ void AssExporter::AddFilter(wxString const& name) { } void AssExporter::AddAutoFilters() { - for (filter_iterator it = filter_list_begin(); it != filter_list_end(); ++it) { - if ((*it)->GetAutoApply()) - filters.push_back(*it); + for (auto filter : *AssExportFilterChain::GetFilterList()) { + if (filter->GetAutoApply()) + filters.push_back(filter); } } @@ -106,9 +106,9 @@ wxArrayString AssExporter::GetAllFilterNames() const { AssFile *AssExporter::ExportTransform(wxWindow *export_dialog, bool copy) { AssFile *subs = copy ? new AssFile(*c->ass) : c->ass; - for (filter_iterator cur = filters.begin(); cur != filters.end(); ++cur) { - (*cur)->LoadSettings(is_default, c); - (*cur)->ProcessSubs(subs, export_dialog); + for (auto filter : filters) { + filter->LoadSettings(is_default, c); + filter->ProcessSubs(subs, export_dialog); } return subs; diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index 95dc0e713..2091ed532 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -87,8 +87,8 @@ void AssFile::Load(const wxString &_filename, wxString const& charset) { bool found_dialogue = false; // Check if the file has at least one style and at least one dialogue line - for (entryIter it = temp.Line.begin(); it != temp.Line.end(); ++it) { - AssEntryType type = it->GetType(); + for (auto const& line : temp.Line) { + AssEntryType type = line.GetType(); if (type == ENTRY_STYLE) found_style = true; if (type == ENTRY_DIALOGUE) found_dialogue = true; if (found_style && found_dialogue) break; @@ -180,8 +180,8 @@ void AssFile::SaveMemory(std::vector &dst) { dst.reserve(0x4000); // Write file - for (entryIter cur = Line.begin(); cur != Line.end(); ++cur) { - wxCharBuffer buffer = (cur->GetEntryData() + "\r\n").utf8_str(); + for (auto const& line : Line) { + wxCharBuffer buffer = (line.GetEntryData() + "\r\n").utf8_str(); copy(buffer.data(), buffer.data() + buffer.length(), back_inserter(dst)); } } @@ -318,10 +318,10 @@ wxString AssFile::GetScriptInfo(wxString key) const { key += ":"; bool GotIn = false; - for (constEntryIter cur = Line.begin(); cur != Line.end(); ++cur) { - if (cur->group == "[Script Info]") { + for (auto const& line : Line) { + if (line.group == "[Script Info]") { GotIn = true; - wxString curText = cur->GetEntryData(); + wxString curText = line.GetEntryData(); if (curText.Lower().StartsWith(key)) return curText.Mid(key.size()).Trim(true).Trim(false); } @@ -343,22 +343,19 @@ void AssFile::SetScriptInfo(wxString const& key, wxString const& value) { entryIter script_info_end; bool found_script_info = false; - for (entryIter cur = Line.begin(); cur != Line.end(); ++cur) { - if (cur->group == "[Script Info]") { + for (auto& line : Line) { + if (line.group == "[Script Info]") { found_script_info = true; - wxString cur_text = cur->GetEntryData().Left(key_size).Lower(); + wxString cur_text = line.GetEntryData().Left(key_size).Lower(); if (cur_text == search_key) { - if (value.empty()) { - delete &*cur; - Line.erase(cur); - } - else { - cur->SetEntryData(key + ": " + value); - } + if (value.empty()) + delete &line; + else + line.SetEntryData(key + ": " + value); return; } - script_info_end = cur; + script_info_end = Line.iterator_to(line); } else if (found_script_info) { if (value.size()) @@ -402,16 +399,16 @@ void AssFile::GetResolution(int &sw,int &sh) const { wxArrayString AssFile::GetStyles() const { wxArrayString styles; - for (constEntryIter cur = Line.begin(); cur != Line.end(); ++cur) { - if (const AssStyle *curstyle = dynamic_cast(&*cur)) + for (auto const& line : Line) { + if (const AssStyle *curstyle = dynamic_cast(&line)) styles.Add(curstyle->name); } return styles; } AssStyle *AssFile::GetStyle(wxString const& name) { - for (entryIter cur = Line.begin(); cur != Line.end(); ++cur) { - AssStyle *curstyle = dynamic_cast(&*cur); + for (auto& line : Line) { + AssStyle *curstyle = dynamic_cast(&line); if (curstyle && curstyle->name == name) return curstyle; } diff --git a/aegisub/src/ass_karaoke.cpp b/aegisub/src/ass_karaoke.cpp index ec2ca9da0..c89ba3590 100644 --- a/aegisub/src/ass_karaoke.cpp +++ b/aegisub/src/ass_karaoke.cpp @@ -41,10 +41,10 @@ wxString AssKaraoke::Syllable::GetText(bool k_tag) const { ret = wxString::Format("{%s%d}", tag_type, (duration + 5) / 10); size_t idx = 0; - for (std::map::const_iterator ovr = ovr_tags.begin(); ovr != ovr_tags.end(); ++ovr) { - ret += text.Mid(idx, ovr->first - idx); - ret += ovr->second; - idx = ovr->first; + for (auto const& ovr : ovr_tags) { + ret += text.Mid(idx, ovr.first - idx); + ret += ovr.second; + idx = ovr.first; } ret += text.Mid(idx); return ret; @@ -67,8 +67,7 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) { syl.duration = 0; syl.tag_type = "\\k"; - for (size_t i = 0; i < line->Blocks.size(); ++i) { - AssDialogueBlock *block = line->Blocks[i]; + for (auto block : line->Blocks) { wxString text = block->GetText(); if (dynamic_cast(block)) { @@ -85,9 +84,7 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) { } else if (AssDialogueBlockOverride *ovr = dynamic_cast(block)) { bool in_tag = false; - for (size_t j = 0; j < ovr->Tags.size(); ++j) { - AssOverrideTag *tag = ovr->Tags[j]; - + for (auto tag : ovr->Tags) { if (tag->IsValid() && tag->Name.Left(2).Lower() == "\\k") { if (in_tag) { syl.ovr_tags[syl.text.size()] += "}"; @@ -112,7 +109,7 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) { else { wxString& otext = syl.ovr_tags[syl.text.size()]; // Merge adjacent override tags - if (j == 0 && otext.size()) + if (otext.size() && otext.Last() == '}') otext.RemoveLast(); else if (!in_tag) otext += "{"; @@ -142,13 +139,13 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) { syls.back().duration += end_time - last_end; else if (last_end > end_time) { // Truncate any syllables that extend past the end of the line - for (size_t i = 0; i < size(); ++i) { - if (syls[i].start_time > end_time) { - syls[i].start_time = end_time; - syls[i].duration = 0; + for (auto& syl : syls) { + if (syl.start_time > end_time) { + syl.start_time = end_time; + syl.duration = 0; } else { - syls[i].duration = std::min(syls[i].duration, end_time - syls[i].start_time); + syl.duration = std::min(syl.duration, end_time - syl.start_time); } } } @@ -170,9 +167,8 @@ wxString AssKaraoke::GetText() const { wxString text; text.reserve(size() * 10); - for (iterator it = begin(); it != end(); ++it) { - text += it->GetText(true); - } + for (auto const& syl : syls) + text += syl.GetText(true); return text; } @@ -182,9 +178,8 @@ wxString AssKaraoke::GetTagType() const { } void AssKaraoke::SetTagType(wxString const& new_type) { - for (size_t i = 0; i < size(); ++i) { - syls[i].tag_type = new_type; - } + for (auto& syl : syls) + syl.tag_type = new_type; } void AssKaraoke::AddSplit(size_t syl_idx, size_t pos) { diff --git a/aegisub/src/ass_override.cpp b/aegisub/src/ass_override.cpp index a30e65a5c..6d7a8f7a4 100644 --- a/aegisub/src/ass_override.cpp +++ b/aegisub/src/ass_override.cpp @@ -95,16 +95,13 @@ void AssDialogueBlockOverride::AddTag(wxString const& tag) { wxString AssDialogueBlockOverride::GetText() { text.clear(); - for (std::vector::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) { - text += **cur; - } + for (auto tag : Tags) + text += *tag; return text; } void AssDialogueBlockOverride::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) { - for (std::vector::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) { - AssOverrideTag *curTag = *cur; - + for (auto curTag : Tags) { // Find parameters for (size_t n = 0; n < curTag->Params.size(); ++n) { AssOverrideParameter *curPar = curTag->Params[n]; @@ -371,16 +368,14 @@ void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto:: } unsigned curPar = 0; - for (size_t n = 0; n < proto_it->params.size(); n++) { - AssOverrideParamProto *curproto = &proto_it->params[n]; - + for (auto& curproto : proto_it->params) { // Create parameter AssOverrideParameter *newparam = new AssOverrideParameter; - newparam->classification = curproto->classification; + newparam->classification = curproto.classification; Params.push_back(newparam); // Check if it's optional and not present - if (!(curproto->optional & parsFlag) || curPar >= totalPars) { + if (!(curproto.optional & parsFlag) || curPar >= totalPars) { newparam->omitted = true; continue; } @@ -393,42 +388,42 @@ void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto:: } wxChar firstChar = curtok[0]; - bool auto4 = (firstChar == '!' || firstChar == '$' || firstChar == '%') && curproto->type != VARDATA_BLOCK; + bool auto4 = (firstChar == '!' || firstChar == '$' || firstChar == '%') && curproto.type != VARDATA_BLOCK; if (auto4) { newparam->Set(curtok); + continue; } - else { - switch (curproto->type) { - case VARDATA_INT: { - long temp; - curtok.ToLong(&temp); - newparam->Set(temp); - break; - } - case VARDATA_FLOAT: { - double temp; - curtok.ToDouble(&temp); - newparam->Set(temp); - break; - } - case VARDATA_TEXT: - newparam->Set(curtok); - break; - case VARDATA_BOOL: { - long temp; - curtok.ToLong(&temp); - newparam->Set(temp != 0); - break; - } - case VARDATA_BLOCK: { - AssDialogueBlockOverride *temp = new AssDialogueBlockOverride(curtok); - temp->ParseTags(); - newparam->Set(temp); - break; - } - default: - break; + + switch (curproto.type) { + case VARDATA_INT: { + long temp; + curtok.ToLong(&temp); + newparam->Set(temp); + break; } + case VARDATA_FLOAT: { + double temp; + curtok.ToDouble(&temp); + newparam->Set(temp); + break; + } + case VARDATA_TEXT: + newparam->Set(curtok); + break; + case VARDATA_BOOL: { + long temp; + curtok.ToLong(&temp); + newparam->Set(temp != 0); + break; + } + case VARDATA_BLOCK: { + AssDialogueBlockOverride *temp = new AssDialogueBlockOverride(curtok); + temp->ParseTags(); + newparam->Set(temp); + break; + } + default: + break; } } } @@ -450,14 +445,14 @@ AssOverrideTag::operator wxString() const { // Add parameters bool any = false; - for (std::vector::const_iterator cur = Params.begin(); cur != Params.end(); ++cur) { - if ((*cur)->GetType() != VARDATA_NONE && !(*cur)->omitted) { - result += (*cur)->Get(); + for (auto param : Params) { + if (param->GetType() != VARDATA_NONE && !param->omitted) { + result += param->Get(); result += ","; any = true; } } - if (any) result = result.Left(result.Length()-1); + if (any) result.resize(result.size() - 1); if (parentheses) result += ")"; return result; diff --git a/aegisub/src/ass_parser.cpp b/aegisub/src/ass_parser.cpp index b1c23b43a..7f1b48806 100644 --- a/aegisub/src/ass_parser.cpp +++ b/aegisub/src/ass_parser.cpp @@ -41,8 +41,8 @@ void AssParser::ParseAttachmentLine(wxString const& data) { bool is_filename = data.StartsWith("fontname: ") || data.StartsWith("filename: "); bool valid_data = data.size() > 0 && data.size() <= 80; - for (size_t i = 0; i < data.size(); ++i) { - if (data[i] < 33 || data[i] >= 97) { + for (auto byte : data) { + if (byte < 33 || byte >= 97) { valid_data = false; break; } diff --git a/aegisub/src/ass_style_storage.cpp b/aegisub/src/ass_style_storage.cpp index 249ea7098..545c859dd 100644 --- a/aegisub/src/ass_style_storage.cpp +++ b/aegisub/src/ass_style_storage.cpp @@ -58,8 +58,8 @@ void AssStyleStorage::Save() const { throw "Failed creating directory for style catalogs"; TextFileWriter file(StandardPaths::DecodePath("?user/catalog/" + storage_name + ".sty"), "UTF-8"); - for (const_iterator cur = begin(); cur != end(); ++cur) - file.WriteLineToFile((*cur)->GetEntryData()); + for (const AssStyle *cur : style) + file.WriteLineToFile(cur->GetEntryData()); } void AssStyleStorage::Load(wxString const& name) { @@ -96,15 +96,15 @@ void AssStyleStorage::Delete(int idx) { wxArrayString AssStyleStorage::GetNames() { wxArrayString names; - for (iterator cur = begin(); cur != end(); ++cur) - names.Add((*cur)->name); + for (const AssStyle *cur : style) + names.Add(cur->name); return names; } AssStyle *AssStyleStorage::GetStyle(wxString const& name) { - for (iterator cur = begin(); cur != end(); ++cur) { - if ((*cur)->name.CmpNoCase(name) == 0) - return *cur; + for (AssStyle *cur : style) { + if (cur->name.CmpNoCase(name) == 0) + return cur; } return 0; } diff --git a/aegisub/src/audio_display.cpp b/aegisub/src/audio_display.cpp index 351298a88..17baed6e2 100644 --- a/aegisub/src/audio_display.cpp +++ b/aegisub/src/audio_display.cpp @@ -835,9 +835,8 @@ void AudioDisplay::PaintMarkers(wxDC &dc, TimeRange updtime) wxDCPenChanger pen_retainer(dc, wxPen()); wxDCBrushChanger brush_retainer(dc, wxBrush()); - for (AudioMarkerVector::iterator marker_i = markers.begin(); marker_i != markers.end(); ++marker_i) + for (const auto marker : markers) { - const AudioMarker *marker = *marker_i; int marker_x = RelativeXFromTime(marker->GetPosition()); dc.SetPen(marker->GetStyle()); @@ -874,23 +873,23 @@ void AudioDisplay::PaintLabels(wxDC &dc, TimeRange updtime) font.SetWeight(wxFONTWEIGHT_BOLD); dc.SetFont(font); dc.SetTextForeground(*wxWHITE); - for (size_t i = 0; i < labels.size(); ++i) + for (auto const& label : labels) { - wxSize extent = dc.GetTextExtent(labels[i].text); - int left = RelativeXFromTime(labels[i].range.begin()); - int width = AbsoluteXFromTime(labels[i].range.length()); + wxSize extent = dc.GetTextExtent(label.text); + int left = RelativeXFromTime(label.range.begin()); + int width = AbsoluteXFromTime(label.range.length()); // If it doesn't fit, truncate if (width < extent.GetWidth()) { dc.SetClippingRegion(left, audio_top + 4, width, extent.GetHeight()); - dc.DrawText(labels[i].text, left, audio_top + 4); + dc.DrawText(label.text, left, audio_top + 4); dc.DestroyClippingRegion(); } // Otherwise center in the range else { - dc.DrawText(labels[i].text, left + (width - extent.GetWidth()) / 2, audio_top + 4); + dc.DrawText(label.text, left + (width - extent.GetWidth()) / 2, audio_top + 4); } } } diff --git a/aegisub/src/audio_karaoke.cpp b/aegisub/src/audio_karaoke.cpp index 91724dde2..830ea09ea 100644 --- a/aegisub/src/audio_karaoke.cpp +++ b/aegisub/src/audio_karaoke.cpp @@ -360,9 +360,9 @@ void AudioKaraoke::SetDisplayText() { spaced_text.clear(); syl_start_points.clear(); syl_start_points.reserve(kara->size()); - for (AssKaraoke::iterator it = kara->begin(); it != kara->end(); ++it) { + for (auto const& syl : *kara) { syl_start_points.push_back(spaced_text.size()); - spaced_text += " " + it->text; + spaced_text += " " + syl.text; } // Get the x-coordinates of the right edge of each character diff --git a/aegisub/src/audio_marker.cpp b/aegisub/src/audio_marker.cpp index 9f92301d6..e7134daae 100644 --- a/aegisub/src/audio_marker.cpp +++ b/aegisub/src/audio_marker.cpp @@ -71,9 +71,8 @@ void AudioMarkerProviderKeyframes::Update() { markers.clear(); markers.reserve(keyframes.size()); - for (size_t i = 0; i < keyframes.size(); ++i) { - markers.push_back(AudioMarkerKeyframe(style.get(), timecodes.TimeAtFrame(keyframes[i], agi::vfr::START))); - } + for (int frame : keyframes) + markers.push_back(AudioMarkerKeyframe(style.get(), timecodes.TimeAtFrame(frame, agi::vfr::START))); AnnounceMarkerMoved(); } diff --git a/aegisub/src/audio_player.cpp b/aegisub/src/audio_player.cpp index adc6b0cc4..a4af83d63 100644 --- a/aegisub/src/audio_player.cpp +++ b/aegisub/src/audio_player.cpp @@ -57,12 +57,12 @@ AudioPlayer* AudioPlayerFactory::GetAudioPlayer(AudioProvider *provider) { if (list.empty()) throw agi::NoAudioPlayersError("No audio players are available.", 0); std::string error; - for (size_t i = 0; i < list.size(); ++i) { + for (auto const& factory_name : list) { try { - return Create(list[i], provider); + return Create(factory_name, provider); } catch (agi::AudioPlayerOpenError const& err) { - error += list[i] + " factory: " + err.GetChainedMessage() + "\n"; + error += factory_name + " factory: " + err.GetChainedMessage() + "\n"; } } throw agi::AudioPlayerOpenError(error, 0); diff --git a/aegisub/src/audio_timing_dialogue.cpp b/aegisub/src/audio_timing_dialogue.cpp index 62a2a12ff..3aa3cd877 100644 --- a/aegisub/src/audio_timing_dialogue.cpp +++ b/aegisub/src/audio_timing_dialogue.cpp @@ -651,8 +651,7 @@ std::vector AudioTimingControllerDialogue::OnLeftClick(int ms, boo { // The use of GetPosition here is important, as otherwise it'll start // after lines ending at the same time as the active line begins - std::vector::iterator it = - lower_bound(markers.begin(), markers.end(), clicked->GetPosition(), marker_ptr_cmp()); + auto it = lower_bound(markers.begin(), markers.end(), clicked->GetPosition(), marker_ptr_cmp()); for(; it != markers.end() && !(*clicked < **it); ++it) ret.push_back(*it); } @@ -692,21 +691,20 @@ void AudioTimingControllerDialogue::SetMarkers(std::vector const& // is effected. int min_ms = ms; int max_ms = ms; - for (size_t i = 0; i < upd_markers.size(); ++i) + for (AudioMarker *upd_marker : upd_markers) { - DialogueTimingMarker *marker = static_cast(upd_markers[i]); + DialogueTimingMarker *marker = static_cast(upd_marker); min_ms = std::min(*marker, min_ms); max_ms = std::max(*marker, max_ms); } - std::vector::iterator - begin = lower_bound(markers.begin(), markers.end(), min_ms, marker_ptr_cmp()), - end = upper_bound(begin, markers.end(), max_ms, marker_ptr_cmp()); + auto begin = lower_bound(markers.begin(), markers.end(), min_ms, marker_ptr_cmp()); + auto end = upper_bound(begin, markers.end(), max_ms, marker_ptr_cmp()); // Update the markers - for (size_t i = 0; i < upd_markers.size(); ++i) + for (AudioMarker *upd_marker : upd_markers) { - DialogueTimingMarker *marker = static_cast(upd_markers[i]); + DialogueTimingMarker *marker = static_cast(upd_marker); marker->SetPosition(ms); modified_lines.insert(marker->GetLine()); } @@ -768,10 +766,10 @@ void AudioTimingControllerDialogue::RegenerateInactiveLines() case 3: // All inactive lines { AssDialogue *active_line = context->selectionController->GetActiveLine(); - for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it) + for (auto& line : context->ass->Line) { - if (&*it != active_line && predicate(*it)) - AddInactiveLine(sel, static_cast(&*it)); + if (&line != active_line && predicate(line)) + AddInactiveLine(sel, static_cast(&line)); } break; } @@ -803,12 +801,12 @@ void AudioTimingControllerDialogue::RegenerateSelectedLines() AssDialogue *active = context->selectionController->GetActiveLine(); SubtitleSelection sel = context->selectionController->GetSelectedSet(); - for (SubtitleSelection::iterator it = sel.begin(); it != sel.end(); ++it) + for (auto line : sel) { - if (*it == active) continue; + if (line == active) continue; selected_lines.push_back(TimeableLine(AudioStyle_Selected, &style_inactive, &style_inactive)); - selected_lines.back().SetLine(*it); + selected_lines.back().SetLine(line); } if (!selected_lines.empty() || !was_empty) @@ -864,14 +862,14 @@ int AudioTimingControllerDialogue::SnapPosition(int position, int snap_range, st const AudioMarker *snap_marker = 0; AudioMarkerVector potential_snaps; GetMarkers(snap_time_range, potential_snaps); - for (AudioMarkerVector::iterator mi = potential_snaps.begin(); mi != potential_snaps.end(); ++mi) + for (auto marker : potential_snaps) { - if ((*mi)->CanSnap() && find(exclude.begin(), exclude.end(), *mi) == exclude.end()) + if (marker->CanSnap() && find(exclude.begin(), exclude.end(), marker) == exclude.end()) { if (!snap_marker) - snap_marker = *mi; - else if (tabs((*mi)->GetPosition() - position) < tabs(snap_marker->GetPosition() - position)) - snap_marker = *mi; + snap_marker = marker; + else if (tabs(marker->GetPosition() - position) < tabs(snap_marker->GetPosition() - position)) + snap_marker = marker; } } diff --git a/aegisub/src/audio_timing_karaoke.cpp b/aegisub/src/audio_timing_karaoke.cpp index bf346143f..4ced111b8 100644 --- a/aegisub/src/audio_timing_karaoke.cpp +++ b/aegisub/src/audio_timing_karaoke.cpp @@ -345,8 +345,8 @@ void AudioTimingControllerKaraoke::ModifyStart(int delta) { bool AudioTimingControllerKaraoke::IsNearbyMarker(int ms, int sensitivity) const { TimeRange range(ms - sensitivity, ms + sensitivity); - for (size_t i = 0; i < markers.size(); ++i) - if (range.contains(markers[i])) + for (auto const& marker : markers) + if (range.contains(marker)) return true; return false; @@ -424,8 +424,8 @@ void AudioTimingControllerKaraoke::OnMarkerDrag(std::vector const& } void AudioTimingControllerKaraoke::GetLabels(TimeRange const& range, std::vector &out) const { - for (size_t i = 0; i < labels.size(); ++i) { - if (range.overlaps(labels[i].range)) - out.push_back(labels[i]); + for (auto const& label : labels) { + if (range.overlaps(label.range)) + out.push_back(label); } } diff --git a/aegisub/src/auto4_base.cpp b/aegisub/src/auto4_base.cpp index 9c8d273a9..a9ff3bebc 100644 --- a/aegisub/src/auto4_base.cpp +++ b/aegisub/src/auto4_base.cpp @@ -353,7 +353,7 @@ namespace Automation4 { void ScriptManager::Remove(Script *script) { - std::vector::iterator i = find(scripts.begin(), scripts.end(), script); + auto i = find(scripts.begin(), scripts.end(), script); if (i != scripts.end()) { delete *i; scripts.erase(i); @@ -380,8 +380,8 @@ namespace Automation4 { const std::vector& ScriptManager::GetMacros() { macros.clear(); - for (std::vector::iterator i = scripts.begin(); i != scripts.end(); ++i) { - std::vector sfs = (*i)->GetMacros(); + for (auto script : scripts) { + std::vector sfs = script->GetMacros(); copy(sfs.begin(), sfs.end(), back_inserter(macros)); } return macros; @@ -500,10 +500,8 @@ namespace Automation4 { wxString scripts_string; wxString autobasefn(lagi_wxString(OPT_GET("Path/Automation/Base")->GetString())); - for (size_t i = 0; i < GetScripts().size(); i++) { - Script *script = GetScripts()[i]; - - if (i != 0) + for (auto script : GetScripts()) { + if (!scripts_string.empty()) scripts_string += "|"; wxString autobase_rel, assfile_rel; @@ -541,7 +539,7 @@ namespace Automation4 { void ScriptFactory::Unregister(ScriptFactory *factory) { - std::vector::iterator i = find(Factories().begin(), Factories().end(), factory); + auto i = find(Factories().begin(), Factories().end(), factory); if (i != Factories().end()) { delete *i; Factories().erase(i); @@ -550,8 +548,8 @@ namespace Automation4 { Script* ScriptFactory::CreateFromFile(wxString const& filename, bool log_errors) { - for (std::vector::iterator i = Factories().begin(); i != Factories().end(); ++i) { - Script *s = (*i)->Produce(filename); + for (auto factory : Factories()) { + Script *s = factory->Produce(filename); if (s) { if (!s->GetLoadedState() && log_errors) { wxLogError(_("An Automation script failed to load. File name: '%s', error reported: %s"), filename, s->GetDescription()); @@ -590,8 +588,7 @@ namespace Automation4 { wxString ScriptFactory::GetWildcardStr() { wxString fnfilter, catchall; - for (size_t i = 0; i < Factories().size(); ++i) { - const ScriptFactory *fact = Factories()[i]; + for (auto fact : Factories()) { if (fact->GetEngineName().empty() || fact->GetFilenamePattern().empty()) continue; diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index 61a5efbf9..3cff8d280 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -408,8 +408,8 @@ namespace Automation4 { lua_pushstring(L, "path"); lua_gettable(L, -3); - for (size_t i = 0; i < include_path.size(); ++i) { - wxCharBuffer p = include_path[i].utf8_str(); + for (wxString const& path : include_path) { + wxCharBuffer p = path.utf8_str(); lua_pushfstring(L, ";%s/?.lua;%s/?/init.lua", p.data(), p.data()); lua_concat(L, 2); } @@ -527,8 +527,8 @@ namespace Automation4 { void LuaScript::RegisterCommand(LuaCommand *command) { - for (size_t i = 0; i < macros.size(); ++i) { - if (macros[i]->name() == command->name()) { + for (auto macro : macros) { + if (macro->name() == command->name()) { luaL_error(L, "A macro named '%s' is already defined in script '%s'", command->StrDisplay(0).utf8_str().data(), name.utf8_str().data()); @@ -840,10 +840,11 @@ namespace Automation4 { lua_newtable(L); int active_idx = -1; - int row = 1; + int row = 0; int idx = 1; - for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it, ++row) { - AssDialogue *diag = dynamic_cast(&*it); + for (auto& line : c->ass->Line) { + ++row; + AssDialogue *diag = dynamic_cast(&line); if (!diag) continue; if (diag == active_line) active_idx = row; diff --git a/aegisub/src/auto4_lua_assfile.cpp b/aegisub/src/auto4_lua_assfile.cpp index 1f2cf7a3b..c97702933 100644 --- a/aegisub/src/auto4_lua_assfile.cpp +++ b/aegisub/src/auto4_lua_assfile.cpp @@ -670,10 +670,10 @@ namespace Automation4 { void LuaAssFile::ProcessingComplete(wxString const& undo_description) { // Apply any pending commits - for (std::deque::iterator it = pending_commits.begin(); it != pending_commits.end(); ++it) { + for (auto const& pc : pending_commits) { ass->Line.clear(); - boost::push_back(ass->Line, it->lines | boost::adaptors::indirected); - ass->Commit(it->mesage, it->modification_type); + boost::push_back(ass->Line, pc.lines | boost::adaptors::indirected); + ass->Commit(pc.mesage, pc.modification_type); } // Commit any changes after the last undo point was set @@ -704,8 +704,8 @@ namespace Automation4 { , modification_type(0) , references(2) { - for (entryIter it = ass->Line.begin(); it != ass->Line.end(); ++it) - lines.push_back(&*it); + for (auto& line : ass->Line) + lines.push_back(&line); // prepare userdata object *static_cast(lua_newuserdata(L, sizeof(LuaAssFile*))) = this; diff --git a/aegisub/src/auto4_lua_dialog.cpp b/aegisub/src/auto4_lua_dialog.cpp index 6668ae7f6..b583435ba 100644 --- a/aegisub/src/auto4_lua_dialog.cpp +++ b/aegisub/src/auto4_lua_dialog.cpp @@ -560,10 +560,8 @@ namespace Automation4 { window = new wxPanel(parent); wxGridBagSizer *s = new wxGridBagSizer(4, 4); - for (size_t i = 0; i < controls.size(); ++i) { - LuaDialogControl *c = controls[i]; + for (auto c : controls) s->Add(c->Create(window), wxGBPosition(c->y, c->x), wxGBSpan(c->height, c->width), c->GetSizerFlags()); - } if (use_buttons) { wxStdDialogButtonSizer *bs = new wxStdDialogButtonSizer(); @@ -616,9 +614,9 @@ namespace Automation4 { // Then read controls back lua_newtable(L); - for (size_t i = 0; i < controls.size(); ++i) { - controls[i]->LuaReadBack(L); - lua_setfield(L, -2, controls[i]->name.utf8_str()); + for (auto control : controls) { + control->LuaReadBack(L); + lua_setfield(L, -2, control->name.utf8_str()); } if (use_buttons) { @@ -633,10 +631,10 @@ namespace Automation4 { wxString res; // Format into "name1:value1|name2:value2|name3:value3|" - for (size_t i = 0; i < controls.size(); ++i) { - if (controls[i]->CanSerialiseValue()) { - wxString sn = inline_string_encode(controls[i]->name); - wxString sv = controls[i]->SerialiseValue(); + for (auto control : controls) { + if (control->CanSerialiseValue()) { + wxString sn = inline_string_encode(control->name); + wxString sv = control->SerialiseValue(); res += wxString::Format("%s:%s|", sn, sv); } } @@ -659,10 +657,9 @@ namespace Automation4 { wxString value = pair.AfterFirst(':'); // Hand value to all controls matching name - for (size_t i = 0; i < controls.size(); ++i) { - if (controls[i]->name == name && controls[i]->CanSerialiseValue()) { - controls[i]->UnserialiseValue(value); - } + for (auto control : controls) { + if (control->name == name && control->CanSerialiseValue()) + control->UnserialiseValue(value); } } } diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index 50c3c844d..3c21b1f29 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -278,8 +278,8 @@ void BaseGrid::UpdateMaps(bool preserve_selected_rows) { index_line_map.clear(); line_index_map.clear(); - for (entryIter cur = context->ass->Line.begin(); cur != context->ass->Line.end(); ++cur) { - if (AssDialogue *curdiag = dynamic_cast(&*cur)) { + for (auto& line : context->ass->Line) { + if (AssDialogue *curdiag = dynamic_cast(&line)) { line_index_map[curdiag] = (int)index_line_map.size(); index_line_map.push_back(curdiag); } @@ -290,15 +290,14 @@ void BaseGrid::UpdateMaps(bool preserve_selected_rows) { // If the file shrank enough that no selected rows are left, select the // last row - if (sel_rows.empty()) { + if (sel_rows.empty()) sel_rows.push_back(index_line_map.size() - 1); - } - else if (sel_rows[0] >= (int)index_line_map.size()) { + else if (sel_rows[0] >= (int)index_line_map.size()) sel_rows[0] = index_line_map.size() - 1; - } - for (size_t i = 0; i < sel_rows.size(); i++) { - if (sel_rows[i] >= (int)index_line_map.size()) break; - sel.insert(index_line_map[sel_rows[i]]); + + for (int row : sel_rows) { + if (row >= (int)index_line_map.size()) break; + sel.insert(index_line_map[row]); } SetSelectedSet(sel); diff --git a/aegisub/src/block_cache.h b/aegisub/src/block_cache.h index 52e7c0263..6990995b7 100644 --- a/aegisub/src/block_cache.h +++ b/aegisub/src/block_cache.h @@ -138,11 +138,10 @@ class DataBlockCache { if (mb.blocks.empty()) return; - for (size_t bi = 0; bi < mb.blocks.size(); ++bi) + for (auto block : mb.blocks) { - BlockT *b = mb.blocks[bi]; - if (b) - factory.DisposeBlock(b); + if (block) + factory.DisposeBlock(block); } mb.blocks.clear(); @@ -205,10 +204,8 @@ public: // Quick way out: get rid of everything if (max_size == 0) { - for (size_t mbi = 0; mbi < data.size(); ++mbi) - { - KillMacroBlock(data[mbi]); - } + for (auto& mb : data) + KillMacroBlock(mb); return; } diff --git a/aegisub/src/charset_detect.cpp b/aegisub/src/charset_detect.cpp index 24c85df4f..b48a851ce 100644 --- a/aegisub/src/charset_detect.cpp +++ b/aegisub/src/charset_detect.cpp @@ -53,34 +53,32 @@ namespace CharSetDetect { wxString GetEncoding(wxString const& filename) { agi::charset::CharsetListDetected list; - agi::charset::CharsetListDetected::const_iterator i_lst; try { - agi::charset::DetectAll(STD_STR(filename), list); + agi::charset::DetectAll(from_wx(filename), list); } catch (const agi::charset::UnknownCharset&) { /// @todo If the charset is unknown we need to display a complete list of character sets. } - if (list.size() > 1) { - // Get choice from user - wxArrayString choices; - - std::string log_choice; - for (i_lst = list.begin(); i_lst != list.end(); ++i_lst) { - choices.Add(lagi_wxString(i_lst->second)); - log_choice.append(" " + i_lst->second); - } - - LOG_I("charset/file") << filename << " (" << log_choice << ")"; - - int choice = wxGetSingleChoiceIndex(_("Aegisub could not narrow down the character set to a single one.\nPlease pick one below:"),_("Choose character set"),choices); - if (choice == -1) throw "Canceled"; - return choices.Item(choice); + if (list.size() == 1) { + auto charset = list.begin(); + LOG_I("charset/file") << filename << " (" << charset->second << ")"; + return charset->second; } - i_lst = list.begin(); - LOG_I("charset/file") << filename << " (" << i_lst->second << ")"; - return i_lst->second; + wxArrayString choices; + std::string log_choice; + + for (auto const& charset : list) { + choices.push_back(to_wx(charset.second)); + log_choice.append(" " + charset.second); + } + + LOG_I("charset/file") << filename << " (" << log_choice << ")"; + + int choice = wxGetSingleChoiceIndex(_("Aegisub could not narrow down the character set to a single one.\nPlease pick one below:"),_("Choose character set"),choices); + if (choice == -1) throw "Canceled"; + return choices[choice]; } } diff --git a/aegisub/src/command/audio.cpp b/aegisub/src/command/audio.cpp index 507d96be5..611f9a2ed 100644 --- a/aegisub/src/command/audio.cpp +++ b/aegisub/src/command/audio.cpp @@ -220,9 +220,9 @@ struct audio_save_clip : public Command { if (sel.empty()) return; AssTime start = INT_MAX, end = 0; - for (SubtitleSelection::iterator it = sel.begin(); it != sel.end(); ++it) { - start = std::min(start, (*it)->Start); - end = std::max(end, (*it)->End); + for (auto line : sel) { + start = std::min(start, line->Start); + end = std::max(end, line->End); } c->audioController->SaveClip( diff --git a/aegisub/src/command/command.cpp b/aegisub/src/command/command.cpp index 19c52dae0..ca0f1cbb8 100644 --- a/aegisub/src/command/command.cpp +++ b/aegisub/src/command/command.cpp @@ -68,8 +68,8 @@ namespace cmd { std::vector get_registered_commands() { std::vector ret; ret.reserve(cmd_map.size()); - for (iterator it = cmd_map.begin(); it != cmd_map.end(); ++it) - ret.push_back(it->first); + for (auto const& it : cmd_map) + ret.push_back(it.first); return ret; } @@ -110,9 +110,8 @@ namespace cmd { } void clear() { - for (std::map::iterator it = cmd_map.begin(); it != cmd_map.end(); ++it) { - delete it->second; - } + for (auto& it : cmd_map) + delete it.second; cmd_map.clear(); } } diff --git a/aegisub/src/command/edit.cpp b/aegisub/src/command/edit.cpp index 9c07b14ce..efe985287 100644 --- a/aegisub/src/command/edit.cpp +++ b/aegisub/src/command/edit.cpp @@ -485,8 +485,8 @@ struct edit_find_replace : public Command { static void copy_lines(agi::Context *c) { wxString data; SubtitleSelection sel = c->selectionController->GetSelectedSet(); - for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { - AssDialogue *diag = dynamic_cast(&*it); + for (auto& line : c->ass->Line) { + AssDialogue *diag = dynamic_cast(&line); if (diag && sel.count(diag)) { if (!data.empty()) data += "\r\n"; @@ -505,8 +505,8 @@ static void delete_lines(agi::Context *c, wxString const& commit_message) { AssDialogue *new_active = 0; bool hit_active = false; - for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { - AssDialogue *diag = dynamic_cast(&*it); + for (auto& line : c->ass->Line) { + AssDialogue *diag = dynamic_cast(&line); if (!diag) continue; if (diag == active) { diff --git a/aegisub/src/command/time.cpp b/aegisub/src/command/time.cpp index 249df269f..3d6f7f21e 100644 --- a/aegisub/src/command/time.cpp +++ b/aegisub/src/command/time.cpp @@ -71,8 +71,8 @@ namespace { if (sel.size() < 2) return false; size_t found = 0; - for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { - AssDialogue *diag = dynamic_cast(&*it); + for (auto& line : c->ass->Line) { + AssDialogue *diag = dynamic_cast(&line); if (!diag) continue; if (sel.count(diag)) { @@ -137,9 +137,9 @@ struct time_frame_current : public validate_video_loaded { int target_start = std::max(0, c->videoController->TimeAtFrame(c->videoController->GetFrameN(), agi::vfr::START)); int shift_by = target_start - active_line->Start; - for (SubtitleSelection::const_iterator it = sel.begin(); it != sel.end(); ++it) { - (*it)->Start = (*it)->Start + shift_by; - (*it)->End = (*it)->End + shift_by; + for (auto line : sel) { + line->Start = line->Start + shift_by; + line->End = line->End + shift_by; } c->ass->Commit(_("shift to frame"), AssFile::COMMIT_DIAG_TIME); @@ -167,11 +167,11 @@ static void snap_subs_video(agi::Context *c, bool set_start) { int start = c->videoController->TimeAtFrame(c->videoController->GetFrameN(), agi::vfr::START); int end = c->videoController->TimeAtFrame(c->videoController->GetFrameN(), agi::vfr::END); - for (SubtitleSelection::const_iterator it = sel.begin(); it != sel.end(); ++it) { - if (set_start || (*it)->Start > start) - (*it)->Start = start; - if (!set_start || (*it)->End < end) - (*it)->End = end; + for (auto line : sel) { + if (set_start || line->Start > start) + line->Start = start; + if (!set_start || line->End < end) + line->End = end; } c->ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME); @@ -201,7 +201,6 @@ struct time_snap_scene : public validate_video_loaded { if (!con->IsLoaded() || !con->KeyFramesLoaded()) return; // Get frames - wxArrayInt sel = c->subsGrid->GetSelection(); int curFrame = con->GetFrameN(); int prev = 0; int next = 0; @@ -229,13 +228,11 @@ struct time_snap_scene : public validate_video_loaded { // Get times int start_ms = con->TimeAtFrame(prev,agi::vfr::START); int end_ms = con->TimeAtFrame(next-1,agi::vfr::END); - AssDialogue *cur; // Update rows - for (size_t i=0;isubsGrid->GetDialogue(sel[i]); - cur->Start = start_ms; - cur->End = end_ms; + for (auto line : c->selectionController->GetSelectedSet()) { + line->Start = start_ms; + line->End = end_ms; } // Commit diff --git a/aegisub/src/dialog_attachments.cpp b/aegisub/src/dialog_attachments.cpp index e649f5bca..56359084f 100644 --- a/aegisub/src/dialog_attachments.cpp +++ b/aegisub/src/dialog_attachments.cpp @@ -102,9 +102,8 @@ void DialogAttachments::UpdateList() { listView->InsertColumn(2, _("Group"), wxLIST_FORMAT_LEFT, 100); // Fill list - for (entryIter cur = ass->Line.begin();cur != ass->Line.end();cur++) { - if (AssAttachment *attach = dynamic_cast(&*cur)) { - // Add item + for (auto& line : ass->Line) { + if (AssAttachment *attach = dynamic_cast(&line)) { int row = listView->GetItemCount(); listView->InsertItem(row,attach->GetFileName(true)); listView->SetItem(row,1,PrettySize(attach->GetSize())); diff --git a/aegisub/src/dialog_automation.cpp b/aegisub/src/dialog_automation.cpp index 3abb295fc..bc985fc63 100644 --- a/aegisub/src/dialog_automation.cpp +++ b/aegisub/src/dialog_automation.cpp @@ -199,16 +199,16 @@ void DialogAutomation::OnAdd(wxCommandEvent &) wxArrayString fnames; diag.GetPaths(fnames); - for (size_t i = 0; i < fnames.size(); ++i) { - wxFileName fnpath(fnames[i]); + for (auto const& fname : fnames) { + wxFileName fnpath(fname); OPT_SET("Path/Last/Automation")->SetString(STD_STR(fnpath.GetPath())); if (has_file(local_manager->GetScripts(), fnpath) || has_file(global_manager->GetScripts(), fnpath)) { - wxLogError("Script '%s' is already loaded", fnames[i]); + wxLogError("Script '%s' is already loaded", fname); continue; } - local_manager->Add(Automation4::ScriptFactory::CreateFromFile(fnames[i], true)); + local_manager->Add(Automation4::ScriptFactory::CreateFromFile(fname, true)); } } diff --git a/aegisub/src/dialog_colorpicker.cpp b/aegisub/src/dialog_colorpicker.cpp index cf4ede75f..3e8136342 100644 --- a/aegisub/src/dialog_colorpicker.cpp +++ b/aegisub/src/dialog_colorpicker.cpp @@ -436,7 +436,7 @@ std::vector ColorPickerRecent::Save() const void ColorPickerRecent::AddColor(agi::Color color) { - std::vector::iterator existing = find(colors.begin(), colors.end(), color); + auto existing = find(colors.begin(), colors.end(), color); if (existing != colors.end()) rotate(colors.begin(), existing, existing + 1); else { diff --git a/aegisub/src/dialog_fonts_collector.cpp b/aegisub/src/dialog_fonts_collector.cpp index 74a9a5fab..5c620b0ed 100644 --- a/aegisub/src/dialog_fonts_collector.cpp +++ b/aegisub/src/dialog_fonts_collector.cpp @@ -117,9 +117,9 @@ class FontsCollectorThread : public wxThread { int64_t total_size = 0; bool allOk = true; - for (std::vector::iterator cur = paths.begin(); cur != paths.end(); ++cur) { + for (wxString const& path : paths) { int ret = 0; - wxFileName cur_fn(*cur); + wxFileName cur_fn(path); total_size += cur_fn.GetSize().GetValue(); switch (oper) { @@ -139,12 +139,12 @@ class FontsCollectorThread : public wxThread { } #endif else - ret = wxCopyFile(*cur, dest, true); + ret = wxCopyFile(path, dest, true); } break; case CopyToZip: { - wxFFileInputStream in(*cur); + wxFFileInputStream in(path); if (!in.IsOk()) ret = false; else { @@ -156,13 +156,13 @@ class FontsCollectorThread : public wxThread { } if (ret == 1) - AppendText(wxString::Format(_("* Copied %s.\n"), *cur), 1); + AppendText(wxString::Format(_("* Copied %s.\n"), path), 1); else if (ret == 2) - AppendText(wxString::Format(_("* %s already exists on destination.\n"), wxFileName(*cur).GetFullName()), 3); + AppendText(wxString::Format(_("* %s already exists on destination.\n"), wxFileName(path).GetFullName()), 3); else if (ret == 3) - AppendText(wxString::Format(_("* Symlinked %s.\n"), *cur), 1); + AppendText(wxString::Format(_("* Symlinked %s.\n"), path), 1); else { - AppendText(wxString::Format(_("* Failed to copy %s.\n"), *cur), 2); + AppendText(wxString::Format(_("* Failed to copy %s.\n"), path), 2); allOk = false; } } diff --git a/aegisub/src/dialog_kara_timing_copy.cpp b/aegisub/src/dialog_kara_timing_copy.cpp index b8cabc7d9..5349c971c 100644 --- a/aegisub/src/dialog_kara_timing_copy.cpp +++ b/aegisub/src/dialog_kara_timing_copy.cpp @@ -240,9 +240,8 @@ void KaraokeLineMatchDisplay::OnPaint(wxPaintEvent &) // Draw matched groups int this_total_matchgroup_render_width = 0; bool scroll_arrows_drawn = false; - for (size_t i = 0; i < matched_groups.size(); ++i) + for (auto& grp : matched_groups) { - MatchGroup &grp = matched_groups[i]; int prev_x = next_x; // Skip groups that would cause the input part to be too far right @@ -273,10 +272,8 @@ void KaraokeLineMatchDisplay::OnPaint(wxPaintEvent &) // Matched source syllables int syl_x = next_x; - for (size_t j = 0; j < grp.src.size(); ++j) - { - syl_x += DrawBoxedText(dc, grp.src[j].text, syl_x, y_line1); - } + for (auto const& syl : grp.src) + syl_x += DrawBoxedText(dc, syl.text, syl_x, y_line1); // Matched destination text { @@ -371,14 +368,11 @@ wxString KaraokeLineMatchDisplay::GetOutputLine() const { wxString res; - for (size_t i = 0; i < matched_groups.size(); ++i) + for (auto const& match : matched_groups) { - const MatchGroup &match = matched_groups[i]; int duration = 0; - for (size_t j = 0; j < match.src.size(); ++j) - { - duration += match.src[j].duration; - } + for (auto const& syl : match.src) + duration += syl.duration; res = wxString::Format("%s{\\k%d}%s", res, duration / 10, match.dst); } @@ -539,12 +533,12 @@ void KaraokeLineMatchDisplay::AutoMatchJapanese() // For the magic number 5, see big comment block above int src_lookahead_max = (lookahead+1)*5; int src_lookahead_pos = 0; - for (std::deque::iterator ss = unmatched_source.begin(); ss != unmatched_source.end(); ++ss) + for (auto const& syl : unmatched_source) { // Check if we've gone too far ahead in the source if (src_lookahead_pos++ >= src_lookahead_max) break; // Otherwise look for a match - if (ss->text.StartsWith(matched_roma)) + if (syl.text.StartsWith(matched_roma)) { // Yay! Time to interpolate. // Special case: If the last source syllable before the matching one is @@ -725,9 +719,8 @@ END_EVENT_TABLE() void DialogKanjiTimer::OnClose(wxCommandEvent &) { OPT_SET("Tool/Kanji Timer/Interpolation")->SetBool(Interpolate->IsChecked()); - for (size_t i = 0; i < LinesToChange.size(); ++i) { - LinesToChange[i].first->Text = LinesToChange[i].second; - } + for (auto& line : LinesToChange) + line.first->Text = line.second; if (LinesToChange.size()) { subs->Commit(_("kanji timing"), AssFile::COMMIT_DIAG_TEXT); diff --git a/aegisub/src/dialog_manager.h b/aegisub/src/dialog_manager.h index e85b6e608..613ada741 100644 --- a/aegisub/src/dialog_manager.h +++ b/aegisub/src/dialog_manager.h @@ -106,9 +106,9 @@ public: } ~DialogManager() { - for (DialogMap::iterator it = created_dialogs.begin(); it != created_dialogs.end(); ++it) { - it->second->Unbind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this); - it->second->Destroy(); + for (auto const& it : created_dialogs) { + it.second->Unbind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this); + it.second->Destroy(); } created_dialogs.clear(); } diff --git a/aegisub/src/dialog_properties.cpp b/aegisub/src/dialog_properties.cpp index 63f00f27a..bf5537f50 100644 --- a/aegisub/src/dialog_properties.cpp +++ b/aegisub/src/dialog_properties.cpp @@ -144,8 +144,8 @@ void DialogProperties::AddProperty(wxSizer *sizer, wxString const& label, wxStri void DialogProperties::OnOK(wxCommandEvent &) { int count = 0; - for (size_t i = 0; i < properties.size(); ++i) - count += SetInfoIfDifferent(properties[i].first, properties[i].second->GetValue()); + for (auto const& prop : properties) + count += SetInfoIfDifferent(prop.first, prop.second->GetValue()); count += SetInfoIfDifferent("PlayResX", ResX->GetValue()); count += SetInfoIfDifferent("PlayResY", ResY->GetValue()); diff --git a/aegisub/src/dialog_resample.cpp b/aegisub/src/dialog_resample.cpp index 374a446cd..5b3486f6e 100644 --- a/aegisub/src/dialog_resample.cpp +++ b/aegisub/src/dialog_resample.cpp @@ -206,9 +206,9 @@ namespace { diag->ParseAssTags(); diag->ProcessParameters(resample_tags, state); - for (size_t i = 0; i < diag->Blocks.size(); ++i) { - if (AssDialogueBlockDrawing *block = dynamic_cast(diag->Blocks[i])) - block->TransformCoords(state->margin[LEFT], state->margin[TOP], state->rx, state->ry); + for (auto block : diag->Blocks) { + if (AssDialogueBlockDrawing *drawing = dynamic_cast(block)) + drawing->TransformCoords(state->margin[LEFT], state->margin[TOP], state->rx, state->ry); } for (size_t i = 0; i < 3; ++i) diff --git a/aegisub/src/dialog_search_replace.cpp b/aegisub/src/dialog_search_replace.cpp index 0f5fa755c..b9de1d985 100644 --- a/aegisub/src/dialog_search_replace.cpp +++ b/aegisub/src/dialog_search_replace.cpp @@ -379,8 +379,8 @@ void SearchReplaceEngine::ReplaceAll() { bool inSel = affect == 1; // Scan - for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it) { - AssDialogue *diag = dynamic_cast(&*it); + for (auto& line : context->ass->Line) { + AssDialogue *diag = dynamic_cast(&line); if (!diag) continue; // Check if row is selected diff --git a/aegisub/src/dialog_selection.cpp b/aegisub/src/dialog_selection.cpp index 122ef7256..97a2e0e7a 100644 --- a/aegisub/src/dialog_selection.cpp +++ b/aegisub/src/dialog_selection.cpp @@ -113,8 +113,8 @@ static std::set process(wxString match_text, bool match_case, int std::function pred = get_predicate(mode, &re, match_case, match_text); std::set matches; - for (entryIter it = ass->Line.begin(); it != ass->Line.end(); ++it) { - AssDialogue *diag = dynamic_cast(&*it); + for (auto& line : ass->Line) { + AssDialogue *diag = dynamic_cast(&line); if (!diag) continue; if (diag->Comment && !comments) continue; if (!diag->Comment && !dialogue) continue; diff --git a/aegisub/src/dialog_shift_times.cpp b/aegisub/src/dialog_shift_times.cpp index 911dc3312..18522e45f 100644 --- a/aegisub/src/dialog_shift_times.cpp +++ b/aegisub/src/dialog_shift_times.cpp @@ -308,8 +308,8 @@ void DialogShiftTimes::LoadHistory() { json::Reader::Read(root, *file); *history = root; - for (json::Array::iterator it = history->begin(); it != history->end(); ++it) - history_box->Append(get_history_string(*it)); + for (auto& history_entry : *history) + history_box->Append(get_history_string(history_entry)); } catch (agi::FileSystemError const& e) { LOG_D("dialog_shift_times/load_history") << "Cannot load shift times history: " << e.GetChainedMessage(); @@ -352,8 +352,8 @@ void DialogShiftTimes::Process(wxCommandEvent &) { int block_start = 0; json::Array shifted_blocks; - for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it) { - AssDialogue *line = dynamic_cast(&*it); + for (auto& entry : context->ass->Line) { + AssDialogue *line = dynamic_cast(&entry); if (!line) continue; ++row_number; diff --git a/aegisub/src/dialog_spellchecker.cpp b/aegisub/src/dialog_spellchecker.cpp index c6582202c..6e5d07e69 100644 --- a/aegisub/src/dialog_spellchecker.cpp +++ b/aegisub/src/dialog_spellchecker.cpp @@ -251,10 +251,10 @@ bool DialogSpellChecker::CheckLine(AssDialogue *active_line, int start_pos, int GetWordBoundaries(active_line->Text, results); int shift = 0; - for (size_t j = 0; j < results.size(); ++j) { - word_start = results[j].first + shift; + for (auto const& result : results) { + word_start = result.first + shift; if (word_start < start_pos) continue; - word_end = results[j].second + shift; + word_end = result.second + shift; wxString word = active_line->Text.Mid(word_start, word_end - word_start); if (auto_ignore.count(word) || spellchecker->CheckWord(from_wx(word))) continue; diff --git a/aegisub/src/dialog_style_editor.cpp b/aegisub/src/dialog_style_editor.cpp index b71e76058..aa0338f9e 100644 --- a/aegisub/src/dialog_style_editor.cpp +++ b/aegisub/src/dialog_style_editor.cpp @@ -87,8 +87,8 @@ class StyleRenamer { found_any = false; do_replace = replace; - for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { - AssDialogue *diag = dynamic_cast(&*it); + for (auto& line : c->ass->Line) { + AssDialogue *diag = dynamic_cast(&line); if (!diag) continue; if (diag->Style == source_name) { @@ -425,9 +425,9 @@ void DialogStyleEditor::Apply(bool apply, bool close) { wxArrayString styles = store ? store->GetNames() : c->ass->GetStyles(); // Check if style name is unique - for (unsigned int i=0;iGetStyle(styles[i]) != style) || (!store && c->ass->GetStyle(styles[i]) != style)) { + for (auto const& style_name : styles) { + if (newStyleName.CmpNoCase(style_name) == 0) { + if ((store && store->GetStyle(style_name) != style) || (!store && c->ass->GetStyle(style_name) != style)) { wxMessageBox("There is already a style with this name. Please choose another name.", "Style name conflict.", wxOK | wxICON_ERROR | wxCENTER); return; } diff --git a/aegisub/src/dialog_style_manager.cpp b/aegisub/src/dialog_style_manager.cpp index 08243e5cd..f591dd869 100644 --- a/aegisub/src/dialog_style_manager.cpp +++ b/aegisub/src/dialog_style_manager.cpp @@ -274,8 +274,8 @@ void DialogStyleManager::LoadCurrentStyles(int commit_type) { CurrentList->Clear(); styleMap.clear(); - for (entryIter cur = c->ass->Line.begin(); cur != c->ass->Line.end(); ++cur) { - if (AssStyle *style = dynamic_cast(&*cur)) { + for (auto& line : c->ass->Line) { + if (AssStyle *style = dynamic_cast(&line)) { CurrentList->Append(style->name); styleMap.push_back(style); } @@ -306,8 +306,8 @@ void DialogStyleManager::UpdateStorage() { Store.Save(); StorageList->Clear(); - for (AssStyleStorage::iterator cur = Store.begin(); cur != Store.end(); ++cur) - StorageList->Append((*cur)->name); + for (auto style : Store) + StorageList->Append(style->name); UpdateButtons(); } @@ -360,9 +360,9 @@ void DialogStyleManager::OnCatalogNew() { // Remove bad characters from the name wxString badchars = wxFileName::GetForbiddenChars(wxPATH_DOS); int badchars_removed = 0; - for (size_t i = 0; i < name.size(); ++i) { - if (badchars.find(name[i]) != badchars.npos) { - name[i] = '_'; + for (wxUniCharRef chr : name) { + if (badchars.find(chr) != badchars.npos) { + chr = '_'; ++badchars_removed; } } @@ -420,8 +420,8 @@ void DialogStyleManager::OnCopyToStorage() { } UpdateStorage(); - for (std::list::iterator name = copied.begin(); name != copied.end(); ++name) - StorageList->SetStringSelection(*name, true); + for (auto const& style_name : copied) + StorageList->SetStringSelection(style_name, true); UpdateButtons(); } @@ -434,7 +434,7 @@ void DialogStyleManager::OnCopyToCurrent() { wxString styleName = StorageList->GetString(selections[i]); bool addStyle = true; - for (std::vector::iterator style = styleMap.begin(); style != styleMap.end(); ++style) { + for (auto style = styleMap.begin(); style != styleMap.end(); ++style) { if ((*style)->name.CmpNoCase(styleName) == 0) { addStyle = false; if (wxYES == wxMessageBox(wxString::Format(_("There is already a style with the name \"%s\" in the current script. Overwrite?"), styleName), _("Style name collision"), wxYES_NO)) { @@ -453,8 +453,8 @@ void DialogStyleManager::OnCopyToCurrent() { c->ass->Commit(_("style copy"), AssFile::COMMIT_STYLES); CurrentList->DeselectAll(); - for (std::list::iterator name = copied.begin(); name != copied.end(); ++name) - CurrentList->SetStringSelection(*name, true); + for (auto const& style_name : copied) + CurrentList->SetStringSelection(style_name, true); UpdateButtons(); } @@ -603,12 +603,12 @@ void DialogStyleManager::OnCurrentImport() { bool modified = false; // Loop through selection - for (size_t i = 0; i < selections.size(); ++i) { + for (auto const& sel : selections) { // Check if there is already a style with that name - int test = CurrentList->FindString(styles[selections[i]], false); + int test = CurrentList->FindString(styles[sel], false); if (test != wxNOT_FOUND) { int answer = wxMessageBox( - wxString::Format(_("There is already a style with the name \"%s\" in the current script. Overwrite?"), styles[selections[i]]), + wxString::Format(_("There is already a style with the name \"%s\" in the current script. Overwrite?"), styles[sel]), _("Style name collision"), wxYES_NO); if (answer == wxYES) { @@ -617,7 +617,7 @@ void DialogStyleManager::OnCurrentImport() { // The result of GetString is used rather than the name // itself to deal with that AssFile::GetStyle is // case-sensitive, but style names are case insensitive - *c->ass->GetStyle(CurrentList->GetString(test)) = *temp.GetStyle(styles[selections[i]]); + *c->ass->GetStyle(CurrentList->GetString(test)) = *temp.GetStyle(styles[sel]); } continue; } @@ -625,7 +625,7 @@ void DialogStyleManager::OnCurrentImport() { // Copy modified = true; AssStyle *tempStyle = new AssStyle; - *tempStyle = *temp.GetStyle(styles[selections[i]]); + *tempStyle = *temp.GetStyle(styles[sel]); c->ass->InsertStyle(tempStyle); } diff --git a/aegisub/src/dialog_translation.cpp b/aegisub/src/dialog_translation.cpp index b5bf94561..5c27bf17c 100644 --- a/aegisub/src/dialog_translation.cpp +++ b/aegisub/src/dialog_translation.cpp @@ -247,8 +247,8 @@ void DialogTranslation::UpdateDisplay() { original_text->SetReadOnly(false); original_text->ClearAll(); - for (size_t i = 0; i < active_line->Blocks.size(); ++i) { - AssDialogueBlock *block = active_line->Blocks[i]; + size_t i = 0; + for (auto block : active_line->Blocks) { if (block->GetType() == BLOCK_PLAIN) { int cur_size = original_text->GetReverseUnicodePosition(original_text->GetLength()); original_text->AppendText(block->GetText()); @@ -259,6 +259,7 @@ void DialogTranslation::UpdateDisplay() { } else if (block->GetType() == BLOCK_OVERRIDE) original_text->AppendText("{" + block->GetText() + "}"); + ++i; } original_text->SetReadOnly(true); diff --git a/aegisub/src/export_fixstyle.cpp b/aegisub/src/export_fixstyle.cpp index 7e3fd7d23..c29ee0625 100644 --- a/aegisub/src/export_fixstyle.cpp +++ b/aegisub/src/export_fixstyle.cpp @@ -53,11 +53,10 @@ void AssFixStylesFilter::ProcessSubs(AssFile *subs, wxWindow *) { for_each(styles.begin(), styles.end(), std::mem_fun_ref(&wxString::MakeLower)); styles.Sort(); - for (entryIter cur=subs->Line.begin();cur!=subs->Line.end();cur++) { - if (AssDialogue *diag = dynamic_cast(&*cur)) { - if (!std::binary_search(styles.begin(), styles.end(), diag->Style.Lower())) { + for (auto& line : subs->Line) { + if (AssDialogue *diag = dynamic_cast(&line)) { + if (!std::binary_search(styles.begin(), styles.end(), diag->Style.Lower())) diag->Style = "Default"; - } } } } diff --git a/aegisub/src/export_framerate.cpp b/aegisub/src/export_framerate.cpp index 00f0287a0..f650557ab 100644 --- a/aegisub/src/export_framerate.cpp +++ b/aegisub/src/export_framerate.cpp @@ -208,24 +208,23 @@ void AssTransformFramerateFilter::TransformTimeTags(wxString name,int n,AssOverr void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) { if (!Input->IsLoaded() || !Output->IsLoaded()) return; - for (entryIter cur=subs->Line.begin();cur!=subs->Line.end();cur++) { - AssDialogue *curDialogue = dynamic_cast(&*cur); + for (auto& entry : subs->Line) { + AssDialogue *curDialogue = dynamic_cast(&entry); + if (!curDialogue) continue; - if (curDialogue) { - line = curDialogue; - newK = 0; - oldK = 0; - newStart = trunc_cs(ConvertTime(curDialogue->Start)); - newEnd = trunc_cs(ConvertTime(curDialogue->End) + 9); + line = curDialogue; + newK = 0; + oldK = 0; + newStart = trunc_cs(ConvertTime(curDialogue->Start)); + newEnd = trunc_cs(ConvertTime(curDialogue->End) + 9); - // Process stuff - curDialogue->ParseAssTags(); - curDialogue->ProcessParameters(TransformTimeTags, this); - curDialogue->Start = newStart; - curDialogue->End = newEnd; - curDialogue->UpdateText(); - curDialogue->ClearBlocks(); - } + // Process stuff + curDialogue->ParseAssTags(); + curDialogue->ProcessParameters(TransformTimeTags, this); + curDialogue->Start = newStart; + curDialogue->End = newEnd; + curDialogue->UpdateText(); + curDialogue->ClearBlocks(); } } diff --git a/aegisub/src/factory_manager.h b/aegisub/src/factory_manager.h index f3be7ddbd..572caac85 100644 --- a/aegisub/src/factory_manager.h +++ b/aegisub/src/factory_manager.h @@ -58,9 +58,8 @@ protected: classes->insert(std::make_pair(name, std::make_pair(hide, function))); } else { - for (size_t i = 0; i < subtypes.size(); i++) { - classes->insert(std::make_pair(name + '/' + subtypes[i], std::make_pair(hide, function))); - } + for (auto const& subtype : subtypes) + classes->insert(std::make_pair(name + '/' + subtype, std::make_pair(hide, function))); } } @@ -81,11 +80,11 @@ public: if (!classes) return list; std::string cmp; std::transform(favourite.begin(), favourite.end(), favourite.begin(), ::tolower); - for (iterator cur = classes->begin(); cur != classes->end(); ++cur) { + for (auto const& cls : *classes) { cmp.clear(); - std::transform(cur->first.begin(), cur->first.end(), std::back_inserter(cmp), ::tolower); - if (cmp == favourite) list.insert(list.begin(), cur->first); - else if (!cur->second.first) list.push_back(cur->first); + std::transform(cls.first.begin(), cls.first.end(), std::back_inserter(cmp), ::tolower); + if (cmp == favourite) list.insert(list.begin(), cls.first); + else if (!cls.second.first) list.push_back(cls.first); } return list; } diff --git a/aegisub/src/ffmpegsource_common.cpp b/aegisub/src/ffmpegsource_common.cpp index a2678b913..e8b5cfc74 100644 --- a/aegisub/src/ffmpegsource_common.cpp +++ b/aegisub/src/ffmpegsource_common.cpp @@ -157,9 +157,9 @@ int FFmpegSourceProvider::AskForTrackSelection(const std::map &Tra std::vector TrackNumbers; wxArrayString Choices; - for (std::map::const_iterator i = TrackList.begin(); i != TrackList.end(); i++) { - Choices.Add(wxString::Format(_("Track %02d: %s"), i->first, i->second)); - TrackNumbers.push_back(i->first); + for (auto const& track : TrackList) { + Choices.Add(wxString::Format(_("Track %02d: %s"), track.first, track.second)); + TrackNumbers.push_back(track.first); } int Choice = wxGetSingleChoiceIndex( diff --git a/aegisub/src/font_file_lister.cpp b/aegisub/src/font_file_lister.cpp index 1b68b4725..e7d16a0f3 100644 --- a/aegisub/src/font_file_lister.cpp +++ b/aegisub/src/font_file_lister.cpp @@ -54,10 +54,9 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) { bool overriden = false; - for (size_t i = 0; i < blocks.size(); ++i) { - if (AssDialogueBlockOverride *ovr = dynamic_cast(blocks[i])) { - for (size_t j = 0; j < ovr->Tags.size(); ++j) { - AssOverrideTag *tag = ovr->Tags[j]; + for (auto block : blocks) { + if (AssDialogueBlockOverride *ovr = dynamic_cast(block)) { + for (auto tag : ovr->Tags) { wxString name = tag->Name; if (name == "\\r") { @@ -78,7 +77,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) { } } } - else if (AssDialogueBlockPlain *txt = dynamic_cast(blocks[i])) { + else if (AssDialogueBlockPlain *txt = dynamic_cast(block)) { wxString text = txt->GetText(); if (text.empty() || (text.size() >= 2 && text.StartsWith("{") && text.EndsWith("}"))) @@ -136,14 +135,14 @@ void FontCollector::ProcessChunk(std::pair const& style) { void FontCollector::PrintUsage(UsageData const& data) { if (data.styles.size()) { status_callback(wxString::Format(_("Used in styles:\n")), 2); - for (std::set::const_iterator it = data.styles.begin(); it != data.styles.end(); ++it) - status_callback(wxString::Format(" - %s\n", *it), 2); + for (auto const& style : data.styles) + status_callback(wxString::Format(" - %s\n", style), 2); } if (data.lines.size()) { status_callback(wxString::Format(_("Used on lines:")), 2); - for (std::set::const_iterator it = data.lines.begin(); it != data.lines.end(); ++it) - status_callback(wxString::Format(" %d", *it), 2); + for (int line : data.lines) + status_callback(wxString::Format(" %d", line), 2); status_callback("\n", 2); } status_callback("\n", 2); @@ -156,15 +155,15 @@ std::vector FontCollector::GetFontPaths(const AssFile *file) { status_callback(_("Parsing file\n"), 0); int index = 0; - for (constEntryIter cur = file->Line.begin(); cur != file->Line.end(); ++cur) { - if (const AssStyle *style = dynamic_cast(&*cur)) { + for (auto const& line : file->Line) { + if (const AssStyle *style = dynamic_cast(&line)) { StyleInfo &info = styles[style->name]; info.facename = style->font; info.bold = style->bold; info.italic = style->italic; used_styles[info].styles.insert(style->name); } - else if (const AssDialogue *diag = dynamic_cast(&*cur)) + else if (const AssDialogue *diag = dynamic_cast(&line)) ProcessDialogueLine(diag, ++index); } diff --git a/aegisub/src/font_file_lister_fontconfig.cpp b/aegisub/src/font_file_lister_fontconfig.cpp index 37e4f4f35..c5a16482a 100644 --- a/aegisub/src/font_file_lister_fontconfig.cpp +++ b/aegisub/src/font_file_lister_fontconfig.cpp @@ -205,9 +205,9 @@ FontFileLister::CollectionResult FontConfigFontFileLister::GetFontPaths(wxString FcCharSet *charset; if (FcPatternGetCharSet(rpat, FC_CHARSET, 0, &charset) == FcResultMatch) { - for (std::set::const_iterator it = characters.begin(); it != characters.end(); ++it) { - if (!FcCharSetHasChar(charset, *it)) - ret.missing += *it; + for (wxUniChar chr : characters) { + if (!FcCharSetHasChar(charset, chr)) + ret.missing += chr; } } diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index a8bb5ea33..30bf98c0c 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -146,8 +146,7 @@ static void get_files_to_load(wxArrayString const& list, wxString &subs, wxStrin }; // Scan list - for (size_t i = 0; i < list.size(); ++i) { - wxFileName file(list[i]); + for (wxFileName file : list) { if (file.IsRelative()) file.MakeAbsolute(); if (!file.FileExists()) continue; diff --git a/aegisub/src/gl_text.cpp b/aegisub/src/gl_text.cpp index 7da92756a..7490250c7 100644 --- a/aegisub/src/gl_text.cpp +++ b/aegisub/src/gl_text.cpp @@ -156,13 +156,10 @@ void OpenGLText::Print(const wxString &text,int x,int y) { } void OpenGLText::DrawString(const wxString &text,int x,int y) { - size_t len = text.Length(); lineHeight = 0; int dx=x,dy=y; - for (size_t i=0;i w) w = dx; @@ -224,8 +217,8 @@ OpenGLTextGlyph const& OpenGLText::CreateGlyph(int n) { // Insert into some texture bool ok = false; - for (unsigned int i=0;iTryToInsert(glyph)) { + for (auto texture : textures) { + if (texture->TryToInsert(glyph)) { ok = true; break; } @@ -239,9 +232,6 @@ OpenGLTextGlyph const& OpenGLText::CreateGlyph(int n) { return glyph; } -/// @brief Texture constructor -/// @param w -/// @param h OpenGLTextTexture::OpenGLTextTexture(OpenGLTextGlyph &glyph) { x = y = nextY = 0; width = std::max(SmallestPowerOf2(glyph.w), 64); diff --git a/aegisub/src/hotkey.cpp b/aegisub/src/hotkey.cpp index fa37e2042..6f1ce77ad 100644 --- a/aegisub/src/hotkey.cpp +++ b/aegisub/src/hotkey.cpp @@ -101,9 +101,9 @@ namespace { name_map[renamed_commands[i][0]] = renamed_commands[i][1]; bool renamed_any = false; - agi::hotkey::Hotkey::HotkeyMap hk_map = hotkey::inst->GetHotkeyMap(); - for (agi::hotkey::Hotkey::HotkeyMap::iterator it = hk_map.begin(); it != hk_map.end(); ) { - std::map::iterator ren = name_map.find(it->first); + auto hk_map = hotkey::inst->GetHotkeyMap(); + for (auto it = hk_map.begin(); it != hk_map.end(); ) { + auto ren = name_map.find(it->first); if (ren != name_map.end()) { hk_map.insert(make_pair(std::string(ren->second), agi::hotkey::Combo(it->second.Context(), ren->second, it->second.Get()))); diff --git a/aegisub/src/hotkey_data_view_model.cpp b/aegisub/src/hotkey_data_view_model.cpp index 7e111e1cd..e392cd847 100644 --- a/aegisub/src/hotkey_data_view_model.cpp +++ b/aegisub/src/hotkey_data_view_model.cpp @@ -117,8 +117,7 @@ public: wxArrayString toks = wxSplit(variant.GetString(), '-'); std::vector keys; keys.resize(toks.size()); - for (size_t i = 0; i < toks.size(); ++i) - keys[i] = STD_STR(toks[i]); + transform(toks.begin(), toks.end(), back_inserter(keys), (std::string(*)(wxString const&))&from_wx); combo = Combo(combo.Context(), combo.CmdName(), keys); cmd_str = combo.Str(); return true; @@ -155,7 +154,7 @@ public: } void Delete(wxDataViewItem const& item) { - for (std::list::iterator it = children.begin(); it != children.end(); ++it) { + for (auto it = children.begin(); it != children.end(); ++it) { if (&*it == item.GetID()) { model->ItemDeleted(wxDataViewItem(this), wxDataViewItem((void*)&*it)); children.erase(it); @@ -165,30 +164,30 @@ public: } void Apply(Hotkey::HotkeyMap *hk_map) { - for_each(children.begin(), children.end(), - bind(&HotkeyModelCombo::Apply, std::placeholders::_1, hk_map)); + for (auto& combo : children) + combo.Apply(hk_map); } void SetFilter(wxRegEx const& new_filter) { std::set old_visible; - for (size_t i = 0; i < visible_items.size(); ++i) - old_visible.insert(static_cast(visible_items[i].GetID())); + for (auto item : visible_items) + old_visible.insert(static_cast(item.GetID())); visible_items.clear(); wxDataViewItemArray added; wxDataViewItemArray removed; - for (std::list::iterator it = children.begin(); it != children.end(); ++it) { - bool was_visible = old_visible.count(&*it) > 0; - bool is_visible = it->IsVisible(new_filter); + for (auto& combo : children) { + bool was_visible = old_visible.count(&combo) > 0; + bool is_visible = combo.IsVisible(new_filter); if (is_visible) - visible_items.push_back(wxDataViewItem(&*it)); + visible_items.push_back(wxDataViewItem(&combo)); if (was_visible && !is_visible) - removed.push_back(wxDataViewItem(&*it)); + removed.push_back(wxDataViewItem(&combo)); if (is_visible && !was_visible) - added.push_back(wxDataViewItem(&*it)); + added.push_back(wxDataViewItem(&combo)); } if (!added.empty()) @@ -222,10 +221,10 @@ public: Hotkey::HotkeyMap const& hk_map = hotkey::inst->GetHotkeyMap(); std::map cat_map; - for (Hotkey::HotkeyMap::const_iterator it = hk_map.begin(); it != hk_map.end(); ++it) { - std::string cat_name = it->second.Context(); + for (auto const& category : hk_map) { + std::string cat_name = category.second.Context(); HotkeyModelCategory *cat; - std::map::iterator cat_it = cat_map.find(cat_name); + auto cat_it = cat_map.find(cat_name); if (cat_it != cat_map.end()) cat = cat_it->second; else { @@ -233,7 +232,7 @@ public: cat = cat_map[cat_name] = &categories.back(); } - cat->AddChild(it->second); + cat->AddChild(category.second); } } @@ -260,8 +259,8 @@ public: unsigned int GetChildren(wxDataViewItemArray &out) const { out.reserve(categories.size()); - for (std::list::const_iterator it = categories.begin(); it != categories.end(); ++it) - out.push_back(wxDataViewItem((void*)&*it)); + for (auto const& category : categories) + out.push_back(wxDataViewItem((void*)&category)); return out.size(); } }; diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index 4cb1b0c8c..e8bc638a7 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -255,9 +255,8 @@ bool AegisubApp::OnInit() { // Get parameter subs StartupLog("Parse command line"); wxArrayString subs; - for (int i=1;ibegin(); - it != mru->end(); - ++it, ++i) - { + for (auto it = mru->begin(); it != mru->end(); ++it, ++i) { items[i]->SetItemLabel(wxString::Format("%s%d %s", i <= 9 ? "&" : "", i + 1, wxFileName(lagi_wxString(*it)).GetFullName())); @@ -209,8 +206,7 @@ public: /// Unregister a dynamic menu item void Remove(wxMenuItem *item) { - std::deque >::iterator it = - find_if(dynamic_items.begin(), dynamic_items.end(), menu_item_cmp(item)); + auto it = find_if(dynamic_items.begin(), dynamic_items.end(), menu_item_cmp(item)); if (it != dynamic_items.end()) dynamic_items.erase(it); it = find_if(static_items.begin(), static_items.end(), menu_item_cmp(item)); @@ -442,17 +438,17 @@ namespace menu { menu_items const& items = get_menu(name); std::auto_ptr menu(new CommandMenuBar(c)); - for (menu_items::const_iterator it = items.begin(); it != items.end(); ++it) { + for (auto const& item : items) { std::string submenu, disp; - read_entry(*it, "submenu", &submenu); - read_entry(*it, "text", &disp); + read_entry(item, "submenu", &submenu); + read_entry(item, "text", &disp); if (!submenu.empty()) { - menu->Append(build_menu(submenu, c, &menu->cm), _(lagi_wxString(disp))); + menu->Append(build_menu(submenu, c, &menu->cm), _(to_wx(disp))); } else { - read_entry(*it, "special", &submenu); + read_entry(item, "special", &submenu); if (submenu == "automation") - menu->Append(new AutomationMenu(c, &menu->cm), _(lagi_wxString(disp))); + menu->Append(new AutomationMenu(c, &menu->cm), _(to_wx(disp))); } } diff --git a/aegisub/src/mkv_wrap.cpp b/aegisub/src/mkv_wrap.cpp index 17cd9904f..2065415d9 100644 --- a/aegisub/src/mkv_wrap.cpp +++ b/aegisub/src/mkv_wrap.cpp @@ -133,8 +133,8 @@ static void read_subtitles(agi::ProgressSink *ps, MatroskaFile *file, MkvStdIO * delete[] readBuf; // Insert into file - for (std::map::iterator it = subList.begin(); it != subList.end(); ++it) { - parser->AddLine(it->second); + for (auto order_value_pair : subList) { + parser->AddLine(order_value_pair.second); } } diff --git a/aegisub/src/preferences.cpp b/aegisub/src/preferences.cpp index 4035b3625..10fdbaedd 100644 --- a/aegisub/src/preferences.cpp +++ b/aegisub/src/preferences.cpp @@ -449,8 +449,8 @@ void Interface_Hotkeys::OnUpdateFilter(wxCommandEvent&) { if (!quick_search->GetValue().empty()) { wxDataViewItemArray contexts; model->GetChildren(wxDataViewItem(0), contexts); - for (size_t i = 0; i < contexts.size(); ++i) - dvc->Expand(contexts[i]); + for (auto const& context : contexts) + dvc->Expand(context); } } @@ -635,14 +635,14 @@ void Preferences::OnOK(wxCommandEvent &event) { } void Preferences::OnApply(wxCommandEvent &) { - for (std::map::iterator cur = pending_changes.begin(); cur != pending_changes.end(); ++cur) { - OPT_SET(cur->first)->Set(cur->second); - delete cur->second; + for (auto const& change : pending_changes) { + OPT_SET(change.first)->Set(change.second); + delete change.second; } pending_changes.clear(); - for (std::deque::iterator it = pending_callbacks.begin(); it != pending_callbacks.end(); ++it) - (*it)(); + for (auto const& thunk : pending_callbacks) + thunk(); pending_callbacks.clear(); applyButton->Enable(false); @@ -653,8 +653,8 @@ void Preferences::OnResetDefault(wxCommandEvent&) { if (wxYES != wxMessageBox(_("Are you sure that you want to restore the defaults? All your settings will be overridden."), _("Restore defaults?"), wxYES_NO)) return; - for (std::deque::iterator it = option_names.begin(); it != option_names.end(); ++it) { - agi::OptionValue *opt = OPT_SET(*it); + for (auto const& opt_name : option_names) { + agi::OptionValue *opt = OPT_SET(opt_name); if (!opt->IsDefault()) opt->Reset(); } @@ -719,7 +719,6 @@ Preferences::Preferences(wxWindow *parent): wxDialog(parent, -1, _("Preferences" } Preferences::~Preferences() { - for (std::map::iterator cur = pending_changes.begin(); cur != pending_changes.end(); ++cur) { - delete cur->second; - } + for (auto& change : pending_changes) + delete change.second; } diff --git a/aegisub/src/scintilla_text_ctrl.cpp b/aegisub/src/scintilla_text_ctrl.cpp index 3a304554c..95f5a25fa 100644 --- a/aegisub/src/scintilla_text_ctrl.cpp +++ b/aegisub/src/scintilla_text_ctrl.cpp @@ -88,10 +88,10 @@ void ScintillaTextCtrl::GetBoundsOfWordAtPosition(int pos,int &start,int &end) { GetWordBoundaries(GetText(), results); // Get boundaries - for (size_t i = 0; i < results.size(); i++) { - if (results[i].first <= pos && results[i].second >= pos) { - start = results[i].first; - end = results[i].second; + for (auto const& result : results) { + if (result.first <= pos && result.second >= pos) { + start = result.first; + end = result.second; return; } } diff --git a/aegisub/src/spellchecker.cpp b/aegisub/src/spellchecker.cpp index 77e3a91d1..bd9055e91 100644 --- a/aegisub/src/spellchecker.cpp +++ b/aegisub/src/spellchecker.cpp @@ -48,14 +48,14 @@ agi::SpellChecker *SpellCheckerFactory::GetSpellChecker() { // Get provider wxString error; - for (unsigned int i=0;i values; - for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { - if (AssDialogue *diag = dynamic_cast(&*it)) + for (auto& line : c->ass->Line) { + if (AssDialogue *diag = dynamic_cast(&line)) values.insert(diag->*field); } values.erase(""); @@ -412,9 +412,7 @@ void SubsEditBox::CommitText(wxString const& desc) { } void SubsEditBox::CommitTimes(TimeField field) { - for (SubtitleSelection::iterator cur = sel.begin(); cur != sel.end(); ++cur) { - AssDialogue *d = *cur; - + for (AssDialogue *d : sel) { if (!initialTimes.count(d)) initialTimes[d] = std::make_pair(d->Start, d->End); diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index 566ab9707..803fc997d 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -281,11 +281,9 @@ void SubsTextEditCtrl::UpdateStyle() { AssDialogue *diag = context ? context->selectionController->GetActiveLine() : 0; bool template_line = diag && diag->Comment && diag->Effect.Lower().StartsWith("template"); - std::vector tokens = agi::ass::TokenizeDialogueBody(text); - std::vector style_ranges = agi::ass::SyntaxHighlight(text, tokens, template_line, spellchecker.get()); - for (size_t i = 0; i < style_ranges.size(); ++i) { - SetStyling(style_ranges[i].length, style_ranges[i].type); - } + auto tokens = agi::ass::TokenizeDialogueBody(text); + for (auto const& style_range : agi::ass::SyntaxHighlight(text, tokens, template_line, spellchecker.get())) + SetStyling(style_range.length, style_range.type); } /// @brief Update call tip @@ -611,32 +609,32 @@ void SubsTextEditCtrl::AddThesaurusEntries(wxMenu &menu) { if (!thesaurus) thesaurus.reset(new Thesaurus); - std::vector result; - thesaurus->Lookup(currentWord, &result); + std::vector results; + thesaurus->Lookup(currentWord, &results); thesSugs.clear(); - if (result.size()) { + if (results.size()) { wxMenu *thesMenu = new wxMenu; int curThesEntry = 0; - for (size_t i = 0; i < result.size(); ++i) { + for (auto const& result : results) { // Single word, insert directly - if (result[i].second.size() == 1) { - thesMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, lagi_wxString(result[i].first)); - thesSugs.push_back(result[i].first); + if (result.second.size() == 1) { + thesMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, lagi_wxString(result.first)); + thesSugs.push_back(result.first); ++curThesEntry; } // Multiple, create submenu else { wxMenu *subMenu = new wxMenu; - for (size_t j = 0; j < result[i].second.size(); ++j) { - subMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, lagi_wxString(result[i].second[j])); - thesSugs.push_back(result[i].second[j]); + for (auto const& sug : result.second) { + subMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, to_wx(sug)); + thesSugs.push_back(sug); ++curThesEntry; } - thesMenu->Append(-1, lagi_wxString(result[i].first), subMenu); + thesMenu->Append(-1, to_wx(result.first), subMenu); } } diff --git a/aegisub/src/subtitle_format.cpp b/aegisub/src/subtitle_format.cpp index 98d52c463..7658e2b5a 100644 --- a/aegisub/src/subtitle_format.cpp +++ b/aegisub/src/subtitle_format.cpp @@ -79,18 +79,18 @@ bool SubtitleFormat::CanWriteFile(wxString const& filename) const { bool SubtitleFormat::CanSave(const AssFile *subs) const { AssStyle defstyle; - for (constEntryIter cur = subs->Line.begin(); cur != subs->Line.end(); ++cur) { + for (auto const& line : subs->Line) { // Check style, if anything non-default is found, return false - if (const AssStyle *curstyle = dynamic_cast(&*cur)) { + if (const AssStyle *curstyle = dynamic_cast(&line)) { if (curstyle->GetEntryData() != defstyle.GetEntryData()) return false; } // Check for attachments, if any is found, return false - if (dynamic_cast(&*cur)) return false; + if (dynamic_cast(&line)) return false; // Check dialog - if (const AssDialogue *curdiag = dynamic_cast(&*cur)) { + if (const AssDialogue *curdiag = dynamic_cast(&line)) { if (curdiag->GetStrippedText() != curdiag->Text) return false; } @@ -164,16 +164,16 @@ agi::vfr::Framerate SubtitleFormat::AskForFPS(bool allow_vfr, bool show_smpte) { } void SubtitleFormat::StripTags(AssFile &file) { - for (entryIter cur = file.Line.begin(); cur != file.Line.end(); ++cur) { - if (AssDialogue *current = dynamic_cast(&*cur)) { + for (auto &line : file.Line) { + if (AssDialogue *current = dynamic_cast(&line)) { current->StripTags(); } } } void SubtitleFormat::ConvertNewlines(AssFile &file, wxString const& newline, bool mergeLineBreaks) { - for (entryIter cur = file.Line.begin(); cur != file.Line.end(); ++cur) { - if (AssDialogue *current = dynamic_cast(&*cur)) { + for (auto &line : file.Line) { + if (AssDialogue *current = dynamic_cast(&line)) { current->Text.Replace("\\h", " "); current->Text.Replace("\\n", newline); current->Text.Replace("\\N", newline); @@ -321,13 +321,13 @@ void SubtitleFormat::LoadFormats() { } void SubtitleFormat::DestroyFormats() { - for (std::list::iterator it = formats.begin(); it != formats.end(); ) + for (auto it = formats.begin(); it != formats.end(); ) delete *it++; } template SubtitleFormat *find_or_throw(Cont &container, Pred pred) { - typename Cont::iterator it = find_if(container.begin(), container.end(), pred); + auto it = find_if(container.begin(), container.end(), pred); if (it == container.end()) throw UnknownSubtitleFormatError("Subtitle format for extension not found", 0); return *it; @@ -349,9 +349,7 @@ wxString SubtitleFormat::GetWildcards(int mode) { wxArrayString all; wxString final; - std::list::iterator curIter; - for (curIter=formats.begin();curIter!=formats.end();curIter++) { - SubtitleFormat *format = *curIter; + for (auto format : formats) { wxArrayString cur = mode == 0 ? format->GetReadWildcards() : format->GetWriteWildcards(); if (cur.empty()) continue; diff --git a/aegisub/src/subtitle_format_ass.cpp b/aegisub/src/subtitle_format_ass.cpp index 903f15b94..f28991e57 100644 --- a/aegisub/src/subtitle_format_ass.cpp +++ b/aegisub/src/subtitle_format_ass.cpp @@ -92,13 +92,13 @@ void AssSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename, bool ssa = filename.Right(4).Lower() == ".ssa"; wxString group = src->Line.front().group; - for (constEntryIter cur = src->Line.begin(); cur != src->Line.end(); ++cur) { + for (auto const& line : src->Line) { // Add a blank line between each group - if (cur->group != group) { + if (line.group != group) { file.WriteLineToFile(""); - group = cur->group; + group = line.group; } - file.WriteLineToFile(ssa ? cur->GetSSAText() : cur->GetEntryData(), true); + file.WriteLineToFile(ssa ? line.GetSSAText() : line.GetEntryData(), true); } } diff --git a/aegisub/src/subtitle_format_ebu3264.cpp b/aegisub/src/subtitle_format_ebu3264.cpp index 190236184..5f98a80c7 100644 --- a/aegisub/src/subtitle_format_ebu3264.cpp +++ b/aegisub/src/subtitle_format_ebu3264.cpp @@ -123,9 +123,8 @@ namespace { void ProcessOverrides(AssDialogueBlockOverride *ob, bool &underline, bool &italic, int &align, bool style_underline, bool style_italic) { - for (std::vector::iterator tag = ob->Tags.begin(); tag != ob->Tags.end(); ++tag) + for (auto t : ob->Tags) { - AssOverrideTag *t = *tag; if (t->Name == "\\u") underline = t->Params[0]->Get(style_underline); else if (t->Name == "\\i") @@ -203,15 +202,15 @@ namespace std::vector new_text; new_text.reserve(text_rows.size()); - for (std::vector::iterator row = text_rows.begin(); row != text_rows.end(); ++row) + for (auto const& row : text_rows) { // Get lengths of each word std::vector word_lengths; - for (EbuTextRow::iterator cur_block = row->begin(); cur_block != row->end(); ++cur_block) + for (auto const& cur_block : row) { - if (cur_block->word_start) + if (cur_block.word_start) word_lengths.push_back(0); - word_lengths.back() += cur_block->text.size(); + word_lengths.back() += cur_block.text.size(); } std::vector split_points = agi::get_wrap_points(word_lengths, (size_t)max_width, (agi::WrapMode)split_type); @@ -219,7 +218,7 @@ namespace if (split_points.empty()) { // Line doesn't need splitting, so copy straight over - new_text.push_back(*row); + new_text.push_back(row); continue; } @@ -227,9 +226,9 @@ namespace new_text.push_back(EbuTextRow()); size_t cur_word = 0; size_t split_point = 0; - for (EbuTextRow::iterator cur_block = row->begin(); cur_block != row->end(); ++cur_block) + for (auto const& cur_block : row) { - if (cur_block->word_start && split_point < split_points.size()) + if (cur_block.word_start && split_point < split_points.size()) { if (split_points[split_point] == cur_word) { @@ -239,7 +238,7 @@ namespace ++cur_word; } - new_text.back().push_back(*cur_block); + new_text.back().push_back(cur_block); } } @@ -249,11 +248,11 @@ namespace bool CheckLineLengths(int max_width) const { - for (std::vector::const_iterator row = text_rows.begin(); row != text_rows.end(); ++row) + for (auto const& row : text_rows) { int line_length = 0; - for (EbuTextRow::const_iterator it = row->begin(); it != row->end(); ++it) - line_length += it->text.size(); + for (auto const& block : row) + line_length += block.text.size(); if (line_length > max_width) // early return as soon as any line is over length @@ -281,9 +280,8 @@ namespace bool underline = style_underline, italic = style_italic; - for (std::vector::iterator bl = line->Blocks.begin(); bl != line->Blocks.end(); ++bl) + for (auto b : line->Blocks) { - AssDialogueBlock *b = *bl; switch (b->GetType()) { case BLOCK_PLAIN: @@ -386,9 +384,9 @@ namespace subs_list.reserve(copy.Line.size()); // convert to intermediate format - for (entryIter orgline = copy.Line.begin(); orgline != copy.Line.end(); ++orgline) + for (auto& orgline : copy.Line) { - AssDialogue *line = dynamic_cast(&*orgline); + AssDialogue *line = dynamic_cast(&orgline); if (!line) continue; // add a new subtitle and work on it @@ -455,35 +453,33 @@ namespace return reinterpret_cast(str.wx_str()); } - std::string convert_subtitle_line(std::vector::const_iterator sub, agi::charset::IconvWrapper *encoder, bool enable_formatting) + std::string convert_subtitle_line(EbuSubtitle const& sub, agi::charset::IconvWrapper *encoder, bool enable_formatting) { std::string fullstring; - for (std::vector::const_iterator row = sub->text_rows.begin(); row != sub->text_rows.end(); ++row) + for (auto const& row : sub.text_rows) { + if (!fullstring.empty()) + fullstring += EBU_FORMAT_LINEBREAK; + // formatting is reset at the start of every row, so keep track per row bool underline = false, italic = false; - for (std::vector::const_iterator block = row->begin(); block != row->end(); ++block) + for (auto const& block : row) { if (enable_formatting) { // insert codes for changed formatting - if (underline != block->underline) - fullstring += EBU_FORMAT_UNDERLINE[block->underline]; - if (italic != block->italic) - fullstring += EBU_FORMAT_ITALIC[block->italic]; + if (underline != block.underline) + fullstring += EBU_FORMAT_UNDERLINE[block.underline]; + if (italic != block.italic) + fullstring += EBU_FORMAT_ITALIC[block.italic]; - underline = block->underline; - italic = block->italic; + underline = block.underline; + italic = block.italic; } // convert text to specified encoding - fullstring += encoder->Convert(std::string(wx_str(block->text), buffer_size(block->text))); + fullstring += encoder->Convert(std::string(wx_str(block.text), buffer_size(block.text))); } - - // check that this is not the last row - if (row+1 != sub->text_rows.end()) - // insert linebreak for non-final lines - fullstring += EBU_FORMAT_LINEBREAK; } return fullstring; } @@ -515,33 +511,33 @@ namespace std::vector tti; tti.reserve(subs_list.size()); - for (std::vector::const_iterator sub = subs_list.begin(); sub != subs_list.end(); ++sub) + for (auto const& sub : subs_list) { std::string fullstring = convert_subtitle_line(sub, encoder.get(), export_settings.display_standard == EbuExportSettings::DSC_Open); // construct a base block that can be copied and filled BlockTTI base; - base.sgn = sub->group_number; + base.sgn = sub.group_number; base.sn = Endian::MachineToLittle(subtitle_number++); base.ebn = 255; - base.cf = sub->comment_flag; + base.cf = sub.comment_flag; memset(base.tf, EBU_FORMAT_UNUSED_SPACE, sizeof(base.tf)); - smpte_at_frame(fps, sub->time_in, base.tci); - smpte_at_frame(fps, sub->time_out, base.tco); - base.cs = sub->cumulative_status; + smpte_at_frame(fps, sub.time_in, base.tci); + smpte_at_frame(fps, sub.time_out, base.tco); + base.cs = sub.cumulative_status; if (export_settings.translate_alignments) { // vertical position - if (sub->vertical_position == EbuSubtitle::PositionTop) + if (sub.vertical_position == EbuSubtitle::PositionTop) base.vp = min_row; - else if (sub->vertical_position == EbuSubtitle::PositionMiddle) - base.vp = std::min(min_row, max_row / 2 - (max_row / 5 * sub->text_rows.size())); - else //if (sub->vertical_position == EbuSubtitle::PositionBottom) + else if (sub.vertical_position == EbuSubtitle::PositionMiddle) + base.vp = std::min(min_row, max_row / 2 - (max_row / 5 * sub.text_rows.size())); + else //if (sub.vertical_position == EbuSubtitle::PositionBottom) base.vp = max_row - 1; - base.jc = sub->justification_code; + base.jc = sub.justification_code; } else { @@ -687,8 +683,6 @@ void Ebu3264SubtitleFormat::WriteFile(const AssFile *src, wxString const& filena // write file agi::io::Save f(STD_STR(filename), true); f.Get().write((const char *)&gsi, sizeof(gsi)); - for (std::vector::iterator block = tti.begin(); block != tti.end(); ++block) - { - f.Get().write((const char *)&*block, sizeof(*block)); - } + for (auto const& block : tti) + f.Get().write((const char *)&block, sizeof(block)); } diff --git a/aegisub/src/subtitle_format_encore.cpp b/aegisub/src/subtitle_format_encore.cpp index c36809d90..2c4264293 100644 --- a/aegisub/src/subtitle_format_encore.cpp +++ b/aegisub/src/subtitle_format_encore.cpp @@ -77,8 +77,8 @@ void EncoreSubtitleFormat::WriteFile(const AssFile *src, wxString const& filenam // Write lines int i = 0; TextFileWriter file(filename, "UTF-8"); - for (constEntryIter cur = copy.Line.begin(); cur != copy.Line.end(); ++cur) { - if (const AssDialogue *current = dynamic_cast(&*cur)) { + for (auto const& line : copy.Line) { + if (const AssDialogue *current = dynamic_cast(&line)) { ++i; file.WriteLineToFile(wxString::Format("%i %s %s %s", i, ft.ToSMPTE(current->Start), ft.ToSMPTE(current->End), current->Text)); } diff --git a/aegisub/src/subtitle_format_microdvd.cpp b/aegisub/src/subtitle_format_microdvd.cpp index 1415b0e25..7495261fa 100644 --- a/aegisub/src/subtitle_format_microdvd.cpp +++ b/aegisub/src/subtitle_format_microdvd.cpp @@ -142,8 +142,8 @@ void MicroDVDSubtitleFormat::WriteFile(const AssFile *src, wxString const& filen } // Write lines - for (constEntryIter cur = copy.Line.begin(); cur != copy.Line.end(); ++cur) { - if (const AssDialogue *current = dynamic_cast(&*cur)) { + for (auto const& line : copy.Line) { + if (const AssDialogue *current = dynamic_cast(&line)) { int start = fps.FrameAtTime(current->Start, agi::vfr::START); int end = fps.FrameAtTime(current->End, agi::vfr::END); diff --git a/aegisub/src/subtitle_format_srt.cpp b/aegisub/src/subtitle_format_srt.cpp index 0f71104d3..24a26a4c2 100644 --- a/aegisub/src/subtitle_format_srt.cpp +++ b/aegisub/src/subtitle_format_srt.cpp @@ -509,8 +509,8 @@ void SRTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename, // Write lines int i=1; - for (constEntryIter cur = copy.Line.begin(); cur != copy.Line.end(); ++cur) { - if (const AssDialogue *current = dynamic_cast(&*cur)) { + for (auto const& line : copy.Line) { + if (const AssDialogue *current = dynamic_cast(&line)) { file.WriteLineToFile(wxString::Format("%d", i++)); file.WriteLineToFile(WriteSRTTime(current->Start) + " --> " + WriteSRTTime(current->End)); file.WriteLineToFile(ConvertTags(current)); @@ -523,26 +523,26 @@ bool SRTSubtitleFormat::CanSave(const AssFile *file) const { wxString supported_tags[] = { "\\b", "\\i", "\\s", "\\u" }; AssStyle defstyle; - for (constEntryIter cur = file->Line.begin(); cur != file->Line.end(); ++cur) { + for (auto const& line : file->Line) { // Check style, if anything non-default is found, return false - if (const AssStyle *curstyle = dynamic_cast(&*cur)) { + if (const AssStyle *curstyle = dynamic_cast(&line)) { if (curstyle->GetEntryData() != defstyle.GetEntryData()) return false; } // Check for attachments, if any is found, return false - if (dynamic_cast(&*cur)) return false; + if (dynamic_cast(&line)) return false; // Check dialogue - if (const AssDialogue *curdiag = dynamic_cast(&*cur)) { + if (const AssDialogue *curdiag = dynamic_cast(&line)) { std::vector blocks = curdiag->ParseTags(); - for (size_t i = 0; i < blocks.size(); ++i) { - AssDialogueBlockOverride *ovr = dynamic_cast(blocks[i]); + for (auto block : blocks) { + AssDialogueBlockOverride *ovr = dynamic_cast(block); if (!ovr) continue; // Verify that all overrides used are supported - for (size_t j = 0; j < ovr->Tags.size(); ++j) { - if (!std::binary_search(supported_tags, supported_tags + 4, ovr->Tags[j]->Name)) { + for (auto tag : ovr->Tags) { + if (!std::binary_search(supported_tags, std::end(supported_tags), tag->Name)) { delete_clear(blocks); return false; } @@ -565,13 +565,12 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const { std::vector blocks = diag->ParseTags(); - for (size_t i = 0; i < blocks.size(); ++i) { - if (AssDialogueBlockOverride* block = dynamic_cast(blocks[i])) { + for (auto block : blocks) { + if (AssDialogueBlockOverride* ovr = dynamic_cast(block)) { // Iterate through overrides - for (size_t j = 0; j < block->Tags.size(); j++) { - AssOverrideTag *tag = block->Tags[j]; + for (auto tag : ovr->Tags) { if (tag->IsValid() && tag->Name.size() == 2) { - std::map::iterator it = tag_states.find(tag->Name[1]); + auto it = tag_states.find(tag->Name[1]); if (it != tag_states.end()) { bool temp = tag->Params[0]->Get(false); if (temp && !it->second) @@ -584,16 +583,16 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const { } } // Plain text - else if (AssDialogueBlockPlain *plain = dynamic_cast(blocks[i])) { + else if (AssDialogueBlockPlain *plain = dynamic_cast(block)) { final += plain->GetText(); } } // Ensure all tags are closed // Otherwise unclosed overrides might affect lines they shouldn't, see bug #809 for example - for (std::map::iterator it = tag_states.begin(); it != tag_states.end(); ++it) { - if (it->second) - final += wxString::Format("", it->first); + for (auto it : tag_states) { + if (it.second) + final += wxString::Format("", it.first); } delete_clear(blocks); diff --git a/aegisub/src/subtitle_format_transtation.cpp b/aegisub/src/subtitle_format_transtation.cpp index ea3b608bd..709119c7e 100644 --- a/aegisub/src/subtitle_format_transtation.cpp +++ b/aegisub/src/subtitle_format_transtation.cpp @@ -75,8 +75,8 @@ void TranStationSubtitleFormat::WriteFile(const AssFile *src, wxString const& fi SmpteFormatter ft(fps); TextFileWriter file(filename, encoding); AssDialogue *prev = 0; - for (entryIter it = copy.Line.begin(); it != copy.Line.end(); ++it) { - AssDialogue *cur = dynamic_cast(&*it); + for (auto& line : copy.Line) { + AssDialogue *cur = dynamic_cast(&line); if (prev && cur) { file.WriteLineToFile(ConvertLine(©, prev, fps, ft, cur->Start)); diff --git a/aegisub/src/subtitle_format_ttxt.cpp b/aegisub/src/subtitle_format_ttxt.cpp index bb19ce9fc..4176b4f0c 100644 --- a/aegisub/src/subtitle_format_ttxt.cpp +++ b/aegisub/src/subtitle_format_ttxt.cpp @@ -135,13 +135,13 @@ AssDialogue *TTXTSubtitleFormat::ProcessLine(wxXmlNode *node, AssDialogue *prev, finalText.reserve(text.size()); bool in = false; bool first = true; - for (size_t i = 0; i < text.size(); ++i) { - if (text[i] == '\'') { + for (auto chr : text) { + if (chr == '\'') { if (!in && !first) finalText += "\\N"; first = false; in = !in; } - else if (in) finalText += text[i]; + else if (in) finalText += chr; } diag->Text = finalText; } @@ -176,8 +176,8 @@ void TTXTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename, // Create lines const AssDialogue *prev = 0; - for (constEntryIter cur = copy.Line.begin(); cur != copy.Line.end(); ++cur) { - const AssDialogue *current = dynamic_cast(&*cur); + for (auto const& line : copy.Line) { + const AssDialogue *current = dynamic_cast(&line); if (current && !current->Comment) { WriteLine(root, prev, current); prev = current; diff --git a/aegisub/src/subtitle_format_txt.cpp b/aegisub/src/subtitle_format_txt.cpp index b134e912a..768b0009e 100644 --- a/aegisub/src/subtitle_format_txt.cpp +++ b/aegisub/src/subtitle_format_txt.cpp @@ -129,8 +129,8 @@ void TXTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename, size_t num_actor_names = 0, num_dialogue_lines = 0; // Detect number of lines with Actor field filled out - for (constEntryIter l = src->Line.begin(); l != src->Line.end(); ++l) { - const AssDialogue *dia = dynamic_cast(&*l); + for (auto const& line : src->Line) { + const AssDialogue *dia = dynamic_cast(&line); if (dia && !dia->Comment) { num_dialogue_lines++; if (!dia->Actor.empty()) @@ -146,8 +146,8 @@ void TXTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename, file.WriteLineToFile(wxString("# Exported by Aegisub ") + GetAegisubShortVersionString()); // Write the file - for (constEntryIter l = src->Line.begin(); l != src->Line.end(); ++l) { - const AssDialogue *dia = dynamic_cast(&*l); + for (auto const& line : src->Line) { + const AssDialogue *dia = dynamic_cast(&line); if (!dia) continue; wxString out_line; @@ -161,10 +161,9 @@ void TXTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename, wxString out_text; if (strip_formatting) { std::vector blocks = dia->ParseTags(); - for (std::vector::iterator block = blocks.begin(); block != blocks.end(); ++block) { - if ((*block)->GetType() == BLOCK_PLAIN) { - out_text += (*block)->GetText(); - } + for (auto block : blocks) { + if (block->GetType() == BLOCK_PLAIN) + out_text += block->GetText(); } delete_clear(blocks); } diff --git a/aegisub/src/subtitles_provider.cpp b/aegisub/src/subtitles_provider.cpp index d210840b1..ac6d39a61 100644 --- a/aegisub/src/subtitles_provider.cpp +++ b/aegisub/src/subtitles_provider.cpp @@ -46,34 +46,28 @@ #include "include/aegisub/subtitles_provider.h" #endif -/// @brief Get provider -/// @return -/// SubtitlesProvider* SubtitlesProviderFactory::GetProvider() { std::vector list = GetClasses(OPT_GET("Subtitle/Provider")->GetString()); if (list.empty()) throw wxString("No subtitle providers are available."); // Get provider wxString error; - for (unsigned int i=0;i csri_providers(CSRISubtitlesProvider::GetSubTypes()); diff --git a/aegisub/src/thesaurus.cpp b/aegisub/src/thesaurus.cpp index 78d30f4bb..3a0cd3720 100644 --- a/aegisub/src/thesaurus.cpp +++ b/aegisub/src/thesaurus.cpp @@ -75,8 +75,8 @@ std::vector Thesaurus::GetLanguageList() const { dat.Sort(); // Drop extensions and the th_ prefix - for (size_t i = 0; i < idx.size(); ++i) idx[i] = idx[i].Mid(3, idx[i].size() - 7); - for (size_t i = 0; i < dat.size(); ++i) dat[i] = dat[i].Mid(3, dat[i].size() - 7); + for (auto& fn : idx) fn = fn.Mid(3, fn.size() - 7); + for (auto& fn : dat) fn = fn.Mid(3, fn.size() - 7); // Verify that each idx has a dat for (size_t i = 0, j = 0; i < idx.size() && j < dat.size(); ) { diff --git a/aegisub/src/threaded_frame_source.cpp b/aegisub/src/threaded_frame_source.cpp index 5a4f21942..cfcacd32c 100644 --- a/aegisub/src/threaded_frame_source.cpp +++ b/aegisub/src/threaded_frame_source.cpp @@ -104,8 +104,8 @@ std::shared_ptr ThreadedFrameSource::ProcFrame(int frameNum, dou // instead muck around with its innards to just temporarily // remove the non-visible lines without deleting them std::deque full; - for (entryIter it = subs->Line.begin(); it != subs->Line.end(); ++it) - full.push_back(&*it); + for (auto& line : subs->Line) + full.push_back(&line); subs->Line.remove_if(invisible_line(time)); try { diff --git a/aegisub/src/toolbar.cpp b/aegisub/src/toolbar.cpp index 14c32e25c..47c2c7f7d 100644 --- a/aegisub/src/toolbar.cpp +++ b/aegisub/src/toolbar.cpp @@ -114,9 +114,7 @@ namespace { bool needs_onidle = false; bool last_was_sep = false; - for (json::Array::const_iterator it = arr.begin(); it != arr.end(); ++it) { - json::String const& command_name = *it; - + for (json::String const& command_name : arr) { if (command_name.empty()) { if (!last_was_sep) AddSeparator(); diff --git a/aegisub/src/utils.cpp b/aegisub/src/utils.cpp index b8c6e85aa..6a796f7bb 100644 --- a/aegisub/src/utils.cpp +++ b/aegisub/src/utils.cpp @@ -402,19 +402,19 @@ class cache_cleaner : public wxThread { } int deleted = 0; - for (std::multimap::iterator i = cachefiles.begin(); i != cachefiles.end(); i++) { + for (auto const& i : cachefiles) { // stop cleaning? if ((total_size <= max_size && cachefiles.size() - deleted <= max_files) || cachefiles.size() - deleted < 2) break; - int64_t fsize = i->second.GetSize().GetValue(); + int64_t fsize = i.second.GetSize().GetValue(); #ifdef __WXMSW__ - int res = wxRemove(i->second.GetFullPath()); + int res = wxRemove(i.second.GetFullPath()); #else - int res = unlink(i->second.GetFullPath().fn_str()); + int res = unlink(i.second.GetFullPath().fn_str()); #endif if (res) { - LOG_D("utils/clean_cache") << "failed to remove file " << STD_STR(i->second.GetFullPath()); + LOG_D("utils/clean_cache") << "failed to remove file " << STD_STR(i.second.GetFullPath()); continue; } diff --git a/aegisub/src/video_out_gl.cpp b/aegisub/src/video_out_gl.cpp index 007704022..04ce41c58 100644 --- a/aegisub/src/video_out_gl.cpp +++ b/aegisub/src/video_out_gl.cpp @@ -289,9 +289,7 @@ void VideoOutGL::UploadFrameData(const AegiVideoFrame& frame) { // Set the row length, needed to be able to upload partial rows CHECK_ERROR(glPixelStorei(GL_UNPACK_ROW_LENGTH, frame.pitch / frame.GetBpp())); - for (unsigned i = 0; i < textureList.size(); i++) { - TextureInfo& ti = textureList[i]; - + for (auto& ti : textureList) { CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, ti.textureID)); CHECK_ERROR(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ti.sourceW, ti.sourceH, format, GL_UNSIGNED_BYTE, frame.data + ti.dataOffset)); diff --git a/aegisub/src/video_provider_cache.cpp b/aegisub/src/video_provider_cache.cpp index 7f754d0b6..7f9ca04f6 100644 --- a/aegisub/src/video_provider_cache.cpp +++ b/aegisub/src/video_provider_cache.cpp @@ -63,7 +63,7 @@ const AegiVideoFrame VideoProviderCache::GetFrame(int n) { size_t total_size = 0; // See if frame is cached - for (boost::container::list::iterator cur = cache.begin(); cur != cache.end(); ++cur) { + for (auto cur = cache.begin(); cur != cache.end(); ++cur) { if (cur->frame_number == n) { cache.push_front(*cur); cache.erase(cur); diff --git a/aegisub/src/video_provider_manager.cpp b/aegisub/src/video_provider_manager.cpp index a78a1663a..d393165e3 100644 --- a/aegisub/src/video_provider_manager.cpp +++ b/aegisub/src/video_provider_manager.cpp @@ -64,32 +64,32 @@ VideoProvider *VideoProviderFactory::GetProvider(wxString video) { bool fileSupported = false; std::string errors; errors.reserve(1024); - for (int i = 0; i < (signed)list.size(); ++i) { + for (auto const& factory : list) { std::string err; try { - VideoProvider *provider = Create(list[i], video); - LOG_I("manager/video/provider") << list[i] << ": opened " << STD_STR(video); + VideoProvider *provider = Create(factory, video); + LOG_I("manager/video/provider") << factory << ": opened " << STD_STR(video); if (provider->WantsCaching()) { return new VideoProviderCache(provider); } return provider; } catch (agi::FileNotFoundError const&) { - err = list[i] + ": file not found."; + err = factory + ": file not found."; // Keep trying other providers as this one may just not be able to // open a valid path } catch (VideoNotSupported const&) { fileFound = true; - err = list[i] + ": video is not in a supported format."; + err = factory + ": video is not in a supported format."; } catch (VideoOpenError const& ex) { fileSupported = true; - err = list[i] + ": " + ex.GetMessage(); + err = factory + ": " + ex.GetMessage(); } catch (agi::vfr::Error const& ex) { fileSupported = true; - err = list[i] + ": " + ex.GetMessage(); + err = factory + ": " + ex.GetMessage(); } errors += err; errors += "\n"; diff --git a/aegisub/src/video_slider.cpp b/aegisub/src/video_slider.cpp index 7ee2999d7..568ceabde 100644 --- a/aegisub/src/video_slider.cpp +++ b/aegisub/src/video_slider.cpp @@ -204,8 +204,8 @@ void VideoSlider::OnPaint(wxPaintEvent &) { int curX; if (OPT_GET("Video/Slider/Show Keyframes")->GetBool()) { dc.SetPen(wxPen(shad)); - for (size_t i=0;i void VisualTool::RemoveSelection(feature_iterator feat) { if (!sel_features.erase(feat) || !feat->line) return; - for (selection_iterator it = sel_features.begin(); it != sel_features.end(); ++it) { - if ((*it)->line == feat->line) return; + for (auto sel : sel_features) { + if (sel->line == feat->line) return; } SubtitleSelection sel = c->selectionController->GetSelectedSet(); @@ -370,13 +370,13 @@ struct scoped_tag_parse { // Find a tag's parameters in a line or return NULL if it's not found static param_vec find_tag(const AssDialogue *line, wxString tag_name) { - for (size_t i = 0; i < line->Blocks.size(); ++i) { - const AssDialogueBlockOverride *ovr = dynamic_cast(line->Blocks[i]); + for (auto block : line->Blocks) { + const AssDialogueBlockOverride *ovr = dynamic_cast(block); if (!ovr) continue; - for (size_t j = 0; j < ovr->Tags.size(); ++j) { - if (ovr->Tags[j]->Name == tag_name) - return &ovr->Tags[j]->Params; + for (auto tag : ovr->Tags) { + if (tag->Name == tag_name) + return &tag->Params; } } diff --git a/aegisub/src/visual_tool_clip.cpp b/aegisub/src/visual_tool_clip.cpp index 8d77ff25a..8e7eb2a46 100644 --- a/aegisub/src/visual_tool_clip.cpp +++ b/aegisub/src/visual_tool_clip.cpp @@ -116,12 +116,11 @@ void VisualToolClip::UpdateHold() { void VisualToolClip::CommitHold() { wxString value = wxString::Format("(%s,%s)", ToScriptCoords(cur_1.Min(cur_2)).Str(), ToScriptCoords(cur_1.Max(cur_2)).Str()); - SubtitleSelection sel = c->selectionController->GetSelectedSet(); - for (SubtitleSelection::iterator it = sel.begin(); it != sel.end(); ++it) { + for (auto line : c->selectionController->GetSelectedSet()) { // This check is technically not correct as it could be outside of an // override block... but that's rather unlikely - bool has_iclip = (*it)->Text.find("\\iclip") != wxString::npos; - SetOverride(*it, has_iclip ? "\\iclip" : "\\clip", value); + bool has_iclip = line->Text.find("\\iclip") != wxString::npos; + SetOverride(line, has_iclip ? "\\iclip" : "\\clip", value); } } diff --git a/aegisub/src/visual_tool_cross.cpp b/aegisub/src/visual_tool_cross.cpp index d816bcd46..c3984e80c 100644 --- a/aegisub/src/visual_tool_cross.cpp +++ b/aegisub/src/visual_tool_cross.cpp @@ -40,21 +40,20 @@ VisualToolCross::~VisualToolCross() { void VisualToolCross::OnDoubleClick() { Vector2D d = ToScriptCoords(mouse_pos) - GetLinePosition(active_line); - SubtitleSelection sel = c->selectionController->GetSelectedSet(); - for (SubtitleSelection::const_iterator it = sel.begin(); it != sel.end(); ++it) { + for (auto line : c->selectionController->GetSelectedSet()) { Vector2D p1, p2; int t1, t2; - if (GetLineMove(*it, p1, p2, t1, t2)) { + if (GetLineMove(line, p1, p2, t1, t2)) { if (t1 > 0 || t2 > 0) - SetOverride(*it, "\\move", wxString::Format("(%s,%s,%d,%d)", Text(p1 + d), Text(p2 + d), t1, t2)); + SetOverride(line, "\\move", wxString::Format("(%s,%s,%d,%d)", Text(p1 + d), Text(p2 + d), t1, t2)); else - SetOverride(*it, "\\move", wxString::Format("(%s,%s)", Text(p1 + d), Text(p2 + d))); + SetOverride(line, "\\move", wxString::Format("(%s,%s)", Text(p1 + d), Text(p2 + d))); } else - SetOverride(*it, "\\pos", "(" + Text(GetLinePosition(*it) + d) + ")"); + SetOverride(line, "\\pos", "(" + Text(GetLinePosition(line) + d) + ")"); - if (Vector2D org = GetLineOrigin(*it)) - SetOverride(*it, "\\org", "(" + Text(org + d) + ")"); + if (Vector2D org = GetLineOrigin(line)) + SetOverride(line, "\\org", "(" + Text(org + d) + ")"); } Commit(_("positioning")); diff --git a/aegisub/src/visual_tool_drag.cpp b/aegisub/src/visual_tool_drag.cpp index 0b39d3ba1..217c44eed 100644 --- a/aegisub/src/visual_tool_drag.cpp +++ b/aegisub/src/visual_tool_drag.cpp @@ -81,8 +81,7 @@ void VisualToolDrag::UpdateToggleButtons() { void VisualToolDrag::OnSubTool(wxCommandEvent &) { // Toggle \move <-> \pos VideoContext *vc = c->videoController; - for (SubtitleSelection::const_iterator cur = selection.begin(); cur != selection.end(); ++cur) { - AssDialogue *line = *cur; + for (auto line : selection) { Vector2D p1, p2; int t1, t2; @@ -115,8 +114,8 @@ void VisualToolDrag::OnFileChanged() { primary = 0; active_feature = features.end(); - for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { - AssDialogue *diag = dynamic_cast(&*it); + for (auto& line : c->ass->Line) { + AssDialogue *diag = dynamic_cast(&line); if (diag && IsDisplayed(diag)) MakeFeatures(diag); } @@ -131,8 +130,8 @@ void VisualToolDrag::OnFrameChanged() { feature_iterator feat = features.begin(); feature_iterator end = features.end(); - for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { - AssDialogue *diag = dynamic_cast(&*it); + for (auto& line : c->ass->Line) { + AssDialogue *diag = dynamic_cast(&line); if (!diag) continue; if (IsDisplayed(diag)) { @@ -282,9 +281,8 @@ bool VisualToolDrag::InitializeDrag(feature_iterator feature) { int time = c->videoController->TimeAtFrame(frame_number) - feature->line->Start; int change = time - feature->time; - for (sel_iterator cur = sel_features.begin(); cur != sel_features.end(); ++cur) { - (*cur)->time += change; - } + for (auto feat : sel_features) + feat->time += change; } return true; } @@ -312,21 +310,20 @@ void VisualToolDrag::UpdateDrag(feature_iterator feature) { void VisualToolDrag::OnDoubleClick() { Vector2D d = ToScriptCoords(mouse_pos) - (primary ? ToScriptCoords(primary->pos) : GetLinePosition(active_line)); - SubtitleSelection sel = c->selectionController->GetSelectedSet(); - for (SubtitleSelection::const_iterator it = sel.begin(); it != sel.end(); ++it) { + for (auto line : c->selectionController->GetSelectedSet()) { Vector2D p1, p2; int t1, t2; - if (GetLineMove(*it, p1, p2, t1, t2)) { + if (GetLineMove(line, p1, p2, t1, t2)) { if (t1 > 0 || t2 > 0) - SetOverride(*it, "\\move", wxString::Format("(%s,%s,%d,%d)", (p1 + d).Str(), (p2 + d).Str(), t1, t2)); + SetOverride(line, "\\move", wxString::Format("(%s,%s,%d,%d)", (p1 + d).Str(), (p2 + d).Str(), t1, t2)); else - SetOverride(*it, "\\move", wxString::Format("(%s,%s)", (p1 + d).Str(), (p2 + d).Str())); + SetOverride(line, "\\move", wxString::Format("(%s,%s)", (p1 + d).Str(), (p2 + d).Str())); } else - SetOverride(*it, "\\pos", (GetLinePosition(*it) + d).PStr()); + SetOverride(line, "\\pos", (GetLinePosition(line) + d).PStr()); - if (Vector2D org = GetLineOrigin(*it)) - SetOverride(*it, "\\org", (org + d).PStr()); + if (Vector2D org = GetLineOrigin(line)) + SetOverride(line, "\\org", (org + d).PStr()); } Commit(_("positioning")); diff --git a/aegisub/src/visual_tool_vector_clip.cpp b/aegisub/src/visual_tool_vector_clip.cpp index 5b8b67fa3..ca7a34ce0 100644 --- a/aegisub/src/visual_tool_vector_clip.cpp +++ b/aegisub/src/visual_tool_vector_clip.cpp @@ -133,10 +133,10 @@ void VisualToolVectorClip::Draw() { // Draw lines connecting the bicubic features gl.SetLineColour(colour[3], 0.9f, 1); - for (Spline::iterator cur = spline.begin(); cur != spline.end(); ++cur) { - if (cur->type == SplineCurve::BICUBIC) { - gl.DrawDashedLine(cur->p1, cur->p2, 6); - gl.DrawDashedLine(cur->p3, cur->p4, 6); + for (auto const& curve : spline) { + if (curve.type == SplineCurve::BICUBIC) { + gl.DrawDashedLine(curve.p1, curve.p2, 6); + gl.DrawDashedLine(curve.p3, curve.p4, 6); } } @@ -204,12 +204,11 @@ void VisualToolVectorClip::Save() { value += wxString::Format("%d,", spline.GetScale()); value += spline.EncodeToAss() + ")"; - SubtitleSelection sel = c->selectionController->GetSelectedSet(); - for (SubtitleSelection::iterator it = sel.begin(); it != sel.end(); ++it) { + for (auto line : c->selectionController->GetSelectedSet()) { // This check is technically not correct as it could be outside of an // override block... but that's rather unlikely - bool has_iclip = (*it)->Text.find("\\iclip") != wxString::npos; - SetOverride(*it, has_iclip ? "\\iclip" : "\\clip", value); + bool has_iclip = line->Text.find("\\iclip") != wxString::npos; + SetOverride(line, has_iclip ? "\\iclip" : "\\clip", value); } }