Use range-based for loops in a bunch of places

This commit is contained in:
Thomas Goyne 2012-11-03 20:53:03 -07:00
parent 8af78a6a61
commit 67df64e879
81 changed files with 585 additions and 682 deletions

View File

@ -235,10 +235,9 @@ std::vector<AssDialogueBlock*> AssDialogue::ParseTags() const {
Blocks.push_back(block); Blocks.push_back(block);
// Look for \p in block // Look for \p in block
std::vector<AssOverrideTag*>::iterator curTag; for (auto tag : block->Tags) {
for (curTag = block->Tags.begin(); curTag != block->Tags.end(); ++curTag) { if (tag->Name == "\\p") {
if ((*curTag)->Name == "\\p") { drawingLevel = tag->Params[0]->Get<int>(0);
drawingLevel = (*curTag)->Params[0]->Get<int>(0);
} }
} }
} }
@ -284,17 +283,17 @@ void AssDialogue::StripTag (wxString tagName) {
wxString final; wxString final;
// Look for blocks // Look for blocks
for (std::vector<AssDialogueBlock*>::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) { for (auto block : Blocks) {
if ((*cur)->GetType() != BLOCK_OVERRIDE) { if (block->GetType() != BLOCK_OVERRIDE) {
final += (*cur)->GetText(); final += block->GetText();
continue; continue;
} }
AssDialogueBlockOverride *over = static_cast<AssDialogueBlockOverride*>(*cur); AssDialogueBlockOverride *over = static_cast<AssDialogueBlockOverride*>(block);
wxString temp; wxString temp;
for (size_t i = 0; i < over->Tags.size(); ++i) { for (auto tag : over->Tags) {
if (over->Tags[i]->Name != tagName) if (tag->Name != tagName)
temp += *over->Tags[i]; temp += *tag;
} }
if (!temp.empty()) if (!temp.empty())
@ -308,13 +307,13 @@ void AssDialogue::StripTag (wxString tagName) {
void AssDialogue::UpdateText () { void AssDialogue::UpdateText () {
if (Blocks.empty()) return; if (Blocks.empty()) return;
Text.clear(); Text.clear();
for (std::vector<AssDialogueBlock*>::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) { for (auto block : Blocks) {
if ((*cur)->GetType() == BLOCK_OVERRIDE) { if (block->GetType() == BLOCK_OVERRIDE) {
Text += "{"; Text += "{";
Text += (*cur)->GetText(); Text += block->GetText();
Text += "}"; 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) { void AssDialogue::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) {
// Apply for all override blocks // Apply for all override blocks
for (std::vector<AssDialogueBlock*>::iterator cur = Blocks.begin(); cur != Blocks.end(); ++cur) { for (auto block : Blocks) {
if ((*cur)->GetType() == BLOCK_OVERRIDE) { if (block->GetType() == BLOCK_OVERRIDE) {
static_cast<AssDialogueBlockOverride*>(*cur)->ProcessParameters(callback, userData); static_cast<AssDialogueBlockOverride*>(block)->ProcessParameters(callback, userData);
} }
} }
} }

View File

@ -89,9 +89,9 @@ void AssExportFilterChain::Clear() {
} }
AssExportFilter *AssExportFilterChain::GetFilter(wxString const& name) { AssExportFilter *AssExportFilterChain::GetFilter(wxString const& name) {
for (FilterList::iterator it = filters()->begin(); it != filters()->end(); ++it) { for (auto filter : *filters()) {
if ((*it)->name == name) if (filter->name == name)
return *it; return filter;
} }
return 0; return 0;
} }

View File

@ -64,16 +64,16 @@ AssExporter::~AssExporter () {
void AssExporter::DrawSettings(wxWindow *parent, wxSizer *target_sizer) { void AssExporter::DrawSettings(wxWindow *parent, wxSizer *target_sizer) {
is_default = false; 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 // Make sure to construct static box sizer first, so it won't overlap
// the controls on wxMac. // the controls on wxMac.
wxSizer *box = new wxStaticBoxSizer(wxVERTICAL, parent, (*cur)->GetName()); wxSizer *box = new wxStaticBoxSizer(wxVERTICAL, parent, filter->GetName());
wxWindow *window = (*cur)->GetConfigDialogWindow(parent, c); wxWindow *window = filter->GetConfigDialogWindow(parent, c);
if (window) { if (window) {
box->Add(window, 0, wxEXPAND, 0); box->Add(window, 0, wxEXPAND, 0);
target_sizer->Add(box, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); target_sizer->Add(box, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
target_sizer->Show(box, false); target_sizer->Show(box, false);
Sizers[(*cur)->GetName()] = box; Sizers[filter->GetName()] = box;
} }
else { else {
delete box; delete box;
@ -90,9 +90,9 @@ void AssExporter::AddFilter(wxString const& name) {
} }
void AssExporter::AddAutoFilters() { void AssExporter::AddAutoFilters() {
for (filter_iterator it = filter_list_begin(); it != filter_list_end(); ++it) { for (auto filter : *AssExportFilterChain::GetFilterList()) {
if ((*it)->GetAutoApply()) if (filter->GetAutoApply())
filters.push_back(*it); filters.push_back(filter);
} }
} }
@ -106,9 +106,9 @@ wxArrayString AssExporter::GetAllFilterNames() const {
AssFile *AssExporter::ExportTransform(wxWindow *export_dialog, bool copy) { AssFile *AssExporter::ExportTransform(wxWindow *export_dialog, bool copy) {
AssFile *subs = copy ? new AssFile(*c->ass) : c->ass; AssFile *subs = copy ? new AssFile(*c->ass) : c->ass;
for (filter_iterator cur = filters.begin(); cur != filters.end(); ++cur) { for (auto filter : filters) {
(*cur)->LoadSettings(is_default, c); filter->LoadSettings(is_default, c);
(*cur)->ProcessSubs(subs, export_dialog); filter->ProcessSubs(subs, export_dialog);
} }
return subs; return subs;

View File

@ -87,8 +87,8 @@ void AssFile::Load(const wxString &_filename, wxString const& charset) {
bool found_dialogue = false; bool found_dialogue = false;
// Check if the file has at least one style and at least one dialogue line // 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) { for (auto const& line : temp.Line) {
AssEntryType type = it->GetType(); AssEntryType type = line.GetType();
if (type == ENTRY_STYLE) found_style = true; if (type == ENTRY_STYLE) found_style = true;
if (type == ENTRY_DIALOGUE) found_dialogue = true; if (type == ENTRY_DIALOGUE) found_dialogue = true;
if (found_style && found_dialogue) break; if (found_style && found_dialogue) break;
@ -180,8 +180,8 @@ void AssFile::SaveMemory(std::vector<char> &dst) {
dst.reserve(0x4000); dst.reserve(0x4000);
// Write file // Write file
for (entryIter cur = Line.begin(); cur != Line.end(); ++cur) { for (auto const& line : Line) {
wxCharBuffer buffer = (cur->GetEntryData() + "\r\n").utf8_str(); wxCharBuffer buffer = (line.GetEntryData() + "\r\n").utf8_str();
copy(buffer.data(), buffer.data() + buffer.length(), back_inserter(dst)); copy(buffer.data(), buffer.data() + buffer.length(), back_inserter(dst));
} }
} }
@ -318,10 +318,10 @@ wxString AssFile::GetScriptInfo(wxString key) const {
key += ":"; key += ":";
bool GotIn = false; bool GotIn = false;
for (constEntryIter cur = Line.begin(); cur != Line.end(); ++cur) { for (auto const& line : Line) {
if (cur->group == "[Script Info]") { if (line.group == "[Script Info]") {
GotIn = true; GotIn = true;
wxString curText = cur->GetEntryData(); wxString curText = line.GetEntryData();
if (curText.Lower().StartsWith(key)) if (curText.Lower().StartsWith(key))
return curText.Mid(key.size()).Trim(true).Trim(false); 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; entryIter script_info_end;
bool found_script_info = false; bool found_script_info = false;
for (entryIter cur = Line.begin(); cur != Line.end(); ++cur) { for (auto& line : Line) {
if (cur->group == "[Script Info]") { if (line.group == "[Script Info]") {
found_script_info = true; 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 (cur_text == search_key) {
if (value.empty()) { if (value.empty())
delete &*cur; delete &line;
Line.erase(cur); else
} line.SetEntryData(key + ": " + value);
else {
cur->SetEntryData(key + ": " + value);
}
return; return;
} }
script_info_end = cur; script_info_end = Line.iterator_to(line);
} }
else if (found_script_info) { else if (found_script_info) {
if (value.size()) if (value.size())
@ -402,16 +399,16 @@ void AssFile::GetResolution(int &sw,int &sh) const {
wxArrayString AssFile::GetStyles() const { wxArrayString AssFile::GetStyles() const {
wxArrayString styles; wxArrayString styles;
for (constEntryIter cur = Line.begin(); cur != Line.end(); ++cur) { for (auto const& line : Line) {
if (const AssStyle *curstyle = dynamic_cast<const AssStyle*>(&*cur)) if (const AssStyle *curstyle = dynamic_cast<const AssStyle*>(&line))
styles.Add(curstyle->name); styles.Add(curstyle->name);
} }
return styles; return styles;
} }
AssStyle *AssFile::GetStyle(wxString const& name) { AssStyle *AssFile::GetStyle(wxString const& name) {
for (entryIter cur = Line.begin(); cur != Line.end(); ++cur) { for (auto& line : Line) {
AssStyle *curstyle = dynamic_cast<AssStyle*>(&*cur); AssStyle *curstyle = dynamic_cast<AssStyle*>(&line);
if (curstyle && curstyle->name == name) if (curstyle && curstyle->name == name)
return curstyle; return curstyle;
} }

View File

@ -41,10 +41,10 @@ wxString AssKaraoke::Syllable::GetText(bool k_tag) const {
ret = wxString::Format("{%s%d}", tag_type, (duration + 5) / 10); ret = wxString::Format("{%s%d}", tag_type, (duration + 5) / 10);
size_t idx = 0; size_t idx = 0;
for (std::map<size_t, wxString>::const_iterator ovr = ovr_tags.begin(); ovr != ovr_tags.end(); ++ovr) { for (auto const& ovr : ovr_tags) {
ret += text.Mid(idx, ovr->first - idx); ret += text.Mid(idx, ovr.first - idx);
ret += ovr->second; ret += ovr.second;
idx = ovr->first; idx = ovr.first;
} }
ret += text.Mid(idx); ret += text.Mid(idx);
return ret; return ret;
@ -67,8 +67,7 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) {
syl.duration = 0; syl.duration = 0;
syl.tag_type = "\\k"; syl.tag_type = "\\k";
for (size_t i = 0; i < line->Blocks.size(); ++i) { for (auto block : line->Blocks) {
AssDialogueBlock *block = line->Blocks[i];
wxString text = block->GetText(); wxString text = block->GetText();
if (dynamic_cast<AssDialogueBlockPlain*>(block)) { if (dynamic_cast<AssDialogueBlockPlain*>(block)) {
@ -85,9 +84,7 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) {
} }
else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block)) { else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block)) {
bool in_tag = false; bool in_tag = false;
for (size_t j = 0; j < ovr->Tags.size(); ++j) { for (auto tag : ovr->Tags) {
AssOverrideTag *tag = ovr->Tags[j];
if (tag->IsValid() && tag->Name.Left(2).Lower() == "\\k") { if (tag->IsValid() && tag->Name.Left(2).Lower() == "\\k") {
if (in_tag) { if (in_tag) {
syl.ovr_tags[syl.text.size()] += "}"; syl.ovr_tags[syl.text.size()] += "}";
@ -112,7 +109,7 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) {
else { else {
wxString& otext = syl.ovr_tags[syl.text.size()]; wxString& otext = syl.ovr_tags[syl.text.size()];
// Merge adjacent override tags // Merge adjacent override tags
if (j == 0 && otext.size()) if (otext.size() && otext.Last() == '}')
otext.RemoveLast(); otext.RemoveLast();
else if (!in_tag) else if (!in_tag)
otext += "{"; otext += "{";
@ -142,13 +139,13 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) {
syls.back().duration += end_time - last_end; syls.back().duration += end_time - last_end;
else if (last_end > end_time) { else if (last_end > end_time) {
// Truncate any syllables that extend past the end of the line // Truncate any syllables that extend past the end of the line
for (size_t i = 0; i < size(); ++i) { for (auto& syl : syls) {
if (syls[i].start_time > end_time) { if (syl.start_time > end_time) {
syls[i].start_time = end_time; syl.start_time = end_time;
syls[i].duration = 0; syl.duration = 0;
} }
else { 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; wxString text;
text.reserve(size() * 10); text.reserve(size() * 10);
for (iterator it = begin(); it != end(); ++it) { for (auto const& syl : syls)
text += it->GetText(true); text += syl.GetText(true);
}
return text; return text;
} }
@ -182,9 +178,8 @@ wxString AssKaraoke::GetTagType() const {
} }
void AssKaraoke::SetTagType(wxString const& new_type) { void AssKaraoke::SetTagType(wxString const& new_type) {
for (size_t i = 0; i < size(); ++i) { for (auto& syl : syls)
syls[i].tag_type = new_type; syl.tag_type = new_type;
}
} }
void AssKaraoke::AddSplit(size_t syl_idx, size_t pos) { void AssKaraoke::AddSplit(size_t syl_idx, size_t pos) {

View File

@ -95,16 +95,13 @@ void AssDialogueBlockOverride::AddTag(wxString const& tag) {
wxString AssDialogueBlockOverride::GetText() { wxString AssDialogueBlockOverride::GetText() {
text.clear(); text.clear();
for (std::vector<AssOverrideTag*>::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) { for (auto tag : Tags)
text += **cur; text += *tag;
}
return text; return text;
} }
void AssDialogueBlockOverride::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) { void AssDialogueBlockOverride::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) {
for (std::vector<AssOverrideTag*>::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) { for (auto curTag : Tags) {
AssOverrideTag *curTag = *cur;
// Find parameters // Find parameters
for (size_t n = 0; n < curTag->Params.size(); ++n) { for (size_t n = 0; n < curTag->Params.size(); ++n) {
AssOverrideParameter *curPar = curTag->Params[n]; AssOverrideParameter *curPar = curTag->Params[n];
@ -371,16 +368,14 @@ void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto::
} }
unsigned curPar = 0; unsigned curPar = 0;
for (size_t n = 0; n < proto_it->params.size(); n++) { for (auto& curproto : proto_it->params) {
AssOverrideParamProto *curproto = &proto_it->params[n];
// Create parameter // Create parameter
AssOverrideParameter *newparam = new AssOverrideParameter; AssOverrideParameter *newparam = new AssOverrideParameter;
newparam->classification = curproto->classification; newparam->classification = curproto.classification;
Params.push_back(newparam); Params.push_back(newparam);
// Check if it's optional and not present // Check if it's optional and not present
if (!(curproto->optional & parsFlag) || curPar >= totalPars) { if (!(curproto.optional & parsFlag) || curPar >= totalPars) {
newparam->omitted = true; newparam->omitted = true;
continue; continue;
} }
@ -393,42 +388,42 @@ void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto::
} }
wxChar firstChar = curtok[0]; wxChar firstChar = curtok[0];
bool auto4 = (firstChar == '!' || firstChar == '$' || firstChar == '%') && curproto->type != VARDATA_BLOCK; bool auto4 = (firstChar == '!' || firstChar == '$' || firstChar == '%') && curproto.type != VARDATA_BLOCK;
if (auto4) { if (auto4) {
newparam->Set(curtok); newparam->Set(curtok);
continue;
} }
else {
switch (curproto->type) { switch (curproto.type) {
case VARDATA_INT: { case VARDATA_INT: {
long temp; long temp;
curtok.ToLong(&temp); curtok.ToLong(&temp);
newparam->Set<int>(temp); newparam->Set<int>(temp);
break; 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<bool>(temp != 0);
break;
}
case VARDATA_BLOCK: {
AssDialogueBlockOverride *temp = new AssDialogueBlockOverride(curtok);
temp->ParseTags();
newparam->Set(temp);
break;
}
default:
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<bool>(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 // Add parameters
bool any = false; bool any = false;
for (std::vector<AssOverrideParameter*>::const_iterator cur = Params.begin(); cur != Params.end(); ++cur) { for (auto param : Params) {
if ((*cur)->GetType() != VARDATA_NONE && !(*cur)->omitted) { if (param->GetType() != VARDATA_NONE && !param->omitted) {
result += (*cur)->Get<wxString>(); result += param->Get<wxString>();
result += ","; result += ",";
any = true; any = true;
} }
} }
if (any) result = result.Left(result.Length()-1); if (any) result.resize(result.size() - 1);
if (parentheses) result += ")"; if (parentheses) result += ")";
return result; return result;

View File

@ -41,8 +41,8 @@ void AssParser::ParseAttachmentLine(wxString const& data) {
bool is_filename = data.StartsWith("fontname: ") || data.StartsWith("filename: "); bool is_filename = data.StartsWith("fontname: ") || data.StartsWith("filename: ");
bool valid_data = data.size() > 0 && data.size() <= 80; bool valid_data = data.size() > 0 && data.size() <= 80;
for (size_t i = 0; i < data.size(); ++i) { for (auto byte : data) {
if (data[i] < 33 || data[i] >= 97) { if (byte < 33 || byte >= 97) {
valid_data = false; valid_data = false;
break; break;
} }

View File

@ -58,8 +58,8 @@ void AssStyleStorage::Save() const {
throw "Failed creating directory for style catalogs"; throw "Failed creating directory for style catalogs";
TextFileWriter file(StandardPaths::DecodePath("?user/catalog/" + storage_name + ".sty"), "UTF-8"); TextFileWriter file(StandardPaths::DecodePath("?user/catalog/" + storage_name + ".sty"), "UTF-8");
for (const_iterator cur = begin(); cur != end(); ++cur) for (const AssStyle *cur : style)
file.WriteLineToFile((*cur)->GetEntryData()); file.WriteLineToFile(cur->GetEntryData());
} }
void AssStyleStorage::Load(wxString const& name) { void AssStyleStorage::Load(wxString const& name) {
@ -96,15 +96,15 @@ void AssStyleStorage::Delete(int idx) {
wxArrayString AssStyleStorage::GetNames() { wxArrayString AssStyleStorage::GetNames() {
wxArrayString names; wxArrayString names;
for (iterator cur = begin(); cur != end(); ++cur) for (const AssStyle *cur : style)
names.Add((*cur)->name); names.Add(cur->name);
return names; return names;
} }
AssStyle *AssStyleStorage::GetStyle(wxString const& name) { AssStyle *AssStyleStorage::GetStyle(wxString const& name) {
for (iterator cur = begin(); cur != end(); ++cur) { for (AssStyle *cur : style) {
if ((*cur)->name.CmpNoCase(name) == 0) if (cur->name.CmpNoCase(name) == 0)
return *cur; return cur;
} }
return 0; return 0;
} }

View File

@ -835,9 +835,8 @@ void AudioDisplay::PaintMarkers(wxDC &dc, TimeRange updtime)
wxDCPenChanger pen_retainer(dc, wxPen()); wxDCPenChanger pen_retainer(dc, wxPen());
wxDCBrushChanger brush_retainer(dc, wxBrush()); 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()); int marker_x = RelativeXFromTime(marker->GetPosition());
dc.SetPen(marker->GetStyle()); dc.SetPen(marker->GetStyle());
@ -874,23 +873,23 @@ void AudioDisplay::PaintLabels(wxDC &dc, TimeRange updtime)
font.SetWeight(wxFONTWEIGHT_BOLD); font.SetWeight(wxFONTWEIGHT_BOLD);
dc.SetFont(font); dc.SetFont(font);
dc.SetTextForeground(*wxWHITE); dc.SetTextForeground(*wxWHITE);
for (size_t i = 0; i < labels.size(); ++i) for (auto const& label : labels)
{ {
wxSize extent = dc.GetTextExtent(labels[i].text); wxSize extent = dc.GetTextExtent(label.text);
int left = RelativeXFromTime(labels[i].range.begin()); int left = RelativeXFromTime(label.range.begin());
int width = AbsoluteXFromTime(labels[i].range.length()); int width = AbsoluteXFromTime(label.range.length());
// If it doesn't fit, truncate // If it doesn't fit, truncate
if (width < extent.GetWidth()) if (width < extent.GetWidth())
{ {
dc.SetClippingRegion(left, audio_top + 4, width, extent.GetHeight()); 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(); dc.DestroyClippingRegion();
} }
// Otherwise center in the range // Otherwise center in the range
else 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);
} }
} }
} }

View File

@ -360,9 +360,9 @@ void AudioKaraoke::SetDisplayText() {
spaced_text.clear(); spaced_text.clear();
syl_start_points.clear(); syl_start_points.clear();
syl_start_points.reserve(kara->size()); 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()); 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 // Get the x-coordinates of the right edge of each character

View File

@ -71,9 +71,8 @@ void AudioMarkerProviderKeyframes::Update() {
markers.clear(); markers.clear();
markers.reserve(keyframes.size()); markers.reserve(keyframes.size());
for (size_t i = 0; i < keyframes.size(); ++i) { for (int frame : keyframes)
markers.push_back(AudioMarkerKeyframe(style.get(), timecodes.TimeAtFrame(keyframes[i], agi::vfr::START))); markers.push_back(AudioMarkerKeyframe(style.get(), timecodes.TimeAtFrame(frame, agi::vfr::START)));
}
AnnounceMarkerMoved(); AnnounceMarkerMoved();
} }

View File

@ -57,12 +57,12 @@ AudioPlayer* AudioPlayerFactory::GetAudioPlayer(AudioProvider *provider) {
if (list.empty()) throw agi::NoAudioPlayersError("No audio players are available.", 0); if (list.empty()) throw agi::NoAudioPlayersError("No audio players are available.", 0);
std::string error; std::string error;
for (size_t i = 0; i < list.size(); ++i) { for (auto const& factory_name : list) {
try { try {
return Create(list[i], provider); return Create(factory_name, provider);
} }
catch (agi::AudioPlayerOpenError const& err) { catch (agi::AudioPlayerOpenError const& err) {
error += list[i] + " factory: " + err.GetChainedMessage() + "\n"; error += factory_name + " factory: " + err.GetChainedMessage() + "\n";
} }
} }
throw agi::AudioPlayerOpenError(error, 0); throw agi::AudioPlayerOpenError(error, 0);

View File

@ -651,8 +651,7 @@ std::vector<AudioMarker*> AudioTimingControllerDialogue::OnLeftClick(int ms, boo
{ {
// The use of GetPosition here is important, as otherwise it'll start // The use of GetPosition here is important, as otherwise it'll start
// after lines ending at the same time as the active line begins // after lines ending at the same time as the active line begins
std::vector<DialogueTimingMarker*>::iterator it = auto it = lower_bound(markers.begin(), markers.end(), clicked->GetPosition(), marker_ptr_cmp());
lower_bound(markers.begin(), markers.end(), clicked->GetPosition(), marker_ptr_cmp());
for(; it != markers.end() && !(*clicked < **it); ++it) for(; it != markers.end() && !(*clicked < **it); ++it)
ret.push_back(*it); ret.push_back(*it);
} }
@ -692,21 +691,20 @@ void AudioTimingControllerDialogue::SetMarkers(std::vector<AudioMarker*> const&
// is effected. // is effected.
int min_ms = ms; int min_ms = ms;
int max_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<DialogueTimingMarker*>(upd_markers[i]); DialogueTimingMarker *marker = static_cast<DialogueTimingMarker*>(upd_marker);
min_ms = std::min<int>(*marker, min_ms); min_ms = std::min<int>(*marker, min_ms);
max_ms = std::max<int>(*marker, max_ms); max_ms = std::max<int>(*marker, max_ms);
} }
std::vector<DialogueTimingMarker*>::iterator auto begin = lower_bound(markers.begin(), markers.end(), min_ms, marker_ptr_cmp());
begin = lower_bound(markers.begin(), markers.end(), min_ms, marker_ptr_cmp()), auto end = upper_bound(begin, markers.end(), max_ms, marker_ptr_cmp());
end = upper_bound(begin, markers.end(), max_ms, marker_ptr_cmp());
// Update the markers // Update the markers
for (size_t i = 0; i < upd_markers.size(); ++i) for (AudioMarker *upd_marker : upd_markers)
{ {
DialogueTimingMarker *marker = static_cast<DialogueTimingMarker*>(upd_markers[i]); DialogueTimingMarker *marker = static_cast<DialogueTimingMarker*>(upd_marker);
marker->SetPosition(ms); marker->SetPosition(ms);
modified_lines.insert(marker->GetLine()); modified_lines.insert(marker->GetLine());
} }
@ -768,10 +766,10 @@ void AudioTimingControllerDialogue::RegenerateInactiveLines()
case 3: // All inactive lines case 3: // All inactive lines
{ {
AssDialogue *active_line = context->selectionController->GetActiveLine(); 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)) if (&line != active_line && predicate(line))
AddInactiveLine(sel, static_cast<AssDialogue*>(&*it)); AddInactiveLine(sel, static_cast<AssDialogue*>(&line));
} }
break; break;
} }
@ -803,12 +801,12 @@ void AudioTimingControllerDialogue::RegenerateSelectedLines()
AssDialogue *active = context->selectionController->GetActiveLine(); AssDialogue *active = context->selectionController->GetActiveLine();
SubtitleSelection sel = context->selectionController->GetSelectedSet(); 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.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) if (!selected_lines.empty() || !was_empty)
@ -864,14 +862,14 @@ int AudioTimingControllerDialogue::SnapPosition(int position, int snap_range, st
const AudioMarker *snap_marker = 0; const AudioMarker *snap_marker = 0;
AudioMarkerVector potential_snaps; AudioMarkerVector potential_snaps;
GetMarkers(snap_time_range, 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) if (!snap_marker)
snap_marker = *mi; snap_marker = marker;
else if (tabs((*mi)->GetPosition() - position) < tabs(snap_marker->GetPosition() - position)) else if (tabs(marker->GetPosition() - position) < tabs(snap_marker->GetPosition() - position))
snap_marker = *mi; snap_marker = marker;
} }
} }

View File

@ -345,8 +345,8 @@ void AudioTimingControllerKaraoke::ModifyStart(int delta) {
bool AudioTimingControllerKaraoke::IsNearbyMarker(int ms, int sensitivity) const { bool AudioTimingControllerKaraoke::IsNearbyMarker(int ms, int sensitivity) const {
TimeRange range(ms - sensitivity, ms + sensitivity); TimeRange range(ms - sensitivity, ms + sensitivity);
for (size_t i = 0; i < markers.size(); ++i) for (auto const& marker : markers)
if (range.contains(markers[i])) if (range.contains(marker))
return true; return true;
return false; return false;
@ -424,8 +424,8 @@ void AudioTimingControllerKaraoke::OnMarkerDrag(std::vector<AudioMarker*> const&
} }
void AudioTimingControllerKaraoke::GetLabels(TimeRange const& range, std::vector<AudioLabel> &out) const { void AudioTimingControllerKaraoke::GetLabels(TimeRange const& range, std::vector<AudioLabel> &out) const {
for (size_t i = 0; i < labels.size(); ++i) { for (auto const& label : labels) {
if (range.overlaps(labels[i].range)) if (range.overlaps(label.range))
out.push_back(labels[i]); out.push_back(label);
} }
} }

View File

@ -353,7 +353,7 @@ namespace Automation4 {
void ScriptManager::Remove(Script *script) void ScriptManager::Remove(Script *script)
{ {
std::vector<Script*>::iterator i = find(scripts.begin(), scripts.end(), script); auto i = find(scripts.begin(), scripts.end(), script);
if (i != scripts.end()) { if (i != scripts.end()) {
delete *i; delete *i;
scripts.erase(i); scripts.erase(i);
@ -380,8 +380,8 @@ namespace Automation4 {
const std::vector<cmd::Command*>& ScriptManager::GetMacros() const std::vector<cmd::Command*>& ScriptManager::GetMacros()
{ {
macros.clear(); macros.clear();
for (std::vector<Script*>::iterator i = scripts.begin(); i != scripts.end(); ++i) { for (auto script : scripts) {
std::vector<cmd::Command*> sfs = (*i)->GetMacros(); std::vector<cmd::Command*> sfs = script->GetMacros();
copy(sfs.begin(), sfs.end(), back_inserter(macros)); copy(sfs.begin(), sfs.end(), back_inserter(macros));
} }
return macros; return macros;
@ -500,10 +500,8 @@ namespace Automation4 {
wxString scripts_string; wxString scripts_string;
wxString autobasefn(lagi_wxString(OPT_GET("Path/Automation/Base")->GetString())); wxString autobasefn(lagi_wxString(OPT_GET("Path/Automation/Base")->GetString()));
for (size_t i = 0; i < GetScripts().size(); i++) { for (auto script : GetScripts()) {
Script *script = GetScripts()[i]; if (!scripts_string.empty())
if (i != 0)
scripts_string += "|"; scripts_string += "|";
wxString autobase_rel, assfile_rel; wxString autobase_rel, assfile_rel;
@ -541,7 +539,7 @@ namespace Automation4 {
void ScriptFactory::Unregister(ScriptFactory *factory) void ScriptFactory::Unregister(ScriptFactory *factory)
{ {
std::vector<ScriptFactory*>::iterator i = find(Factories().begin(), Factories().end(), factory); auto i = find(Factories().begin(), Factories().end(), factory);
if (i != Factories().end()) { if (i != Factories().end()) {
delete *i; delete *i;
Factories().erase(i); Factories().erase(i);
@ -550,8 +548,8 @@ namespace Automation4 {
Script* ScriptFactory::CreateFromFile(wxString const& filename, bool log_errors) Script* ScriptFactory::CreateFromFile(wxString const& filename, bool log_errors)
{ {
for (std::vector<ScriptFactory*>::iterator i = Factories().begin(); i != Factories().end(); ++i) { for (auto factory : Factories()) {
Script *s = (*i)->Produce(filename); Script *s = factory->Produce(filename);
if (s) { if (s) {
if (!s->GetLoadedState() && log_errors) { if (!s->GetLoadedState() && log_errors) {
wxLogError(_("An Automation script failed to load. File name: '%s', error reported: %s"), filename, s->GetDescription()); 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 ScriptFactory::GetWildcardStr()
{ {
wxString fnfilter, catchall; wxString fnfilter, catchall;
for (size_t i = 0; i < Factories().size(); ++i) { for (auto fact : Factories()) {
const ScriptFactory *fact = Factories()[i];
if (fact->GetEngineName().empty() || fact->GetFilenamePattern().empty()) if (fact->GetEngineName().empty() || fact->GetFilenamePattern().empty())
continue; continue;

View File

@ -408,8 +408,8 @@ namespace Automation4 {
lua_pushstring(L, "path"); lua_pushstring(L, "path");
lua_gettable(L, -3); lua_gettable(L, -3);
for (size_t i = 0; i < include_path.size(); ++i) { for (wxString const& path : include_path) {
wxCharBuffer p = include_path[i].utf8_str(); wxCharBuffer p = path.utf8_str();
lua_pushfstring(L, ";%s/?.lua;%s/?/init.lua", p.data(), p.data()); lua_pushfstring(L, ";%s/?.lua;%s/?/init.lua", p.data(), p.data());
lua_concat(L, 2); lua_concat(L, 2);
} }
@ -527,8 +527,8 @@ namespace Automation4 {
void LuaScript::RegisterCommand(LuaCommand *command) void LuaScript::RegisterCommand(LuaCommand *command)
{ {
for (size_t i = 0; i < macros.size(); ++i) { for (auto macro : macros) {
if (macros[i]->name() == command->name()) { if (macro->name() == command->name()) {
luaL_error(L, luaL_error(L,
"A macro named '%s' is already defined in script '%s'", "A macro named '%s' is already defined in script '%s'",
command->StrDisplay(0).utf8_str().data(), name.utf8_str().data()); command->StrDisplay(0).utf8_str().data(), name.utf8_str().data());
@ -840,10 +840,11 @@ namespace Automation4 {
lua_newtable(L); lua_newtable(L);
int active_idx = -1; int active_idx = -1;
int row = 1; int row = 0;
int idx = 1; int idx = 1;
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it, ++row) { for (auto& line : c->ass->Line) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it); ++row;
AssDialogue *diag = dynamic_cast<AssDialogue*>(&line);
if (!diag) continue; if (!diag) continue;
if (diag == active_line) active_idx = row; if (diag == active_line) active_idx = row;

View File

@ -670,10 +670,10 @@ namespace Automation4 {
void LuaAssFile::ProcessingComplete(wxString const& undo_description) void LuaAssFile::ProcessingComplete(wxString const& undo_description)
{ {
// Apply any pending commits // Apply any pending commits
for (std::deque<PendingCommit>::iterator it = pending_commits.begin(); it != pending_commits.end(); ++it) { for (auto const& pc : pending_commits) {
ass->Line.clear(); ass->Line.clear();
boost::push_back(ass->Line, it->lines | boost::adaptors::indirected); boost::push_back(ass->Line, pc.lines | boost::adaptors::indirected);
ass->Commit(it->mesage, it->modification_type); ass->Commit(pc.mesage, pc.modification_type);
} }
// Commit any changes after the last undo point was set // Commit any changes after the last undo point was set
@ -704,8 +704,8 @@ namespace Automation4 {
, modification_type(0) , modification_type(0)
, references(2) , references(2)
{ {
for (entryIter it = ass->Line.begin(); it != ass->Line.end(); ++it) for (auto& line : ass->Line)
lines.push_back(&*it); lines.push_back(&line);
// prepare userdata object // prepare userdata object
*static_cast<LuaAssFile**>(lua_newuserdata(L, sizeof(LuaAssFile*))) = this; *static_cast<LuaAssFile**>(lua_newuserdata(L, sizeof(LuaAssFile*))) = this;

View File

@ -560,10 +560,8 @@ namespace Automation4 {
window = new wxPanel(parent); window = new wxPanel(parent);
wxGridBagSizer *s = new wxGridBagSizer(4, 4); wxGridBagSizer *s = new wxGridBagSizer(4, 4);
for (size_t i = 0; i < controls.size(); ++i) { for (auto c : controls)
LuaDialogControl *c = controls[i];
s->Add(c->Create(window), wxGBPosition(c->y, c->x), wxGBSpan(c->height, c->width), c->GetSizerFlags()); s->Add(c->Create(window), wxGBPosition(c->y, c->x), wxGBSpan(c->height, c->width), c->GetSizerFlags());
}
if (use_buttons) { if (use_buttons) {
wxStdDialogButtonSizer *bs = new wxStdDialogButtonSizer(); wxStdDialogButtonSizer *bs = new wxStdDialogButtonSizer();
@ -616,9 +614,9 @@ namespace Automation4 {
// Then read controls back // Then read controls back
lua_newtable(L); lua_newtable(L);
for (size_t i = 0; i < controls.size(); ++i) { for (auto control : controls) {
controls[i]->LuaReadBack(L); control->LuaReadBack(L);
lua_setfield(L, -2, controls[i]->name.utf8_str()); lua_setfield(L, -2, control->name.utf8_str());
} }
if (use_buttons) { if (use_buttons) {
@ -633,10 +631,10 @@ namespace Automation4 {
wxString res; wxString res;
// Format into "name1:value1|name2:value2|name3:value3|" // Format into "name1:value1|name2:value2|name3:value3|"
for (size_t i = 0; i < controls.size(); ++i) { for (auto control : controls) {
if (controls[i]->CanSerialiseValue()) { if (control->CanSerialiseValue()) {
wxString sn = inline_string_encode(controls[i]->name); wxString sn = inline_string_encode(control->name);
wxString sv = controls[i]->SerialiseValue(); wxString sv = control->SerialiseValue();
res += wxString::Format("%s:%s|", sn, sv); res += wxString::Format("%s:%s|", sn, sv);
} }
} }
@ -659,10 +657,9 @@ namespace Automation4 {
wxString value = pair.AfterFirst(':'); wxString value = pair.AfterFirst(':');
// Hand value to all controls matching name // Hand value to all controls matching name
for (size_t i = 0; i < controls.size(); ++i) { for (auto control : controls) {
if (controls[i]->name == name && controls[i]->CanSerialiseValue()) { if (control->name == name && control->CanSerialiseValue())
controls[i]->UnserialiseValue(value); control->UnserialiseValue(value);
}
} }
} }
} }

View File

@ -278,8 +278,8 @@ void BaseGrid::UpdateMaps(bool preserve_selected_rows) {
index_line_map.clear(); index_line_map.clear();
line_index_map.clear(); line_index_map.clear();
for (entryIter cur = context->ass->Line.begin(); cur != context->ass->Line.end(); ++cur) { for (auto& line : context->ass->Line) {
if (AssDialogue *curdiag = dynamic_cast<AssDialogue*>(&*cur)) { if (AssDialogue *curdiag = dynamic_cast<AssDialogue*>(&line)) {
line_index_map[curdiag] = (int)index_line_map.size(); line_index_map[curdiag] = (int)index_line_map.size();
index_line_map.push_back(curdiag); 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 // If the file shrank enough that no selected rows are left, select the
// last row // last row
if (sel_rows.empty()) { if (sel_rows.empty())
sel_rows.push_back(index_line_map.size() - 1); 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; sel_rows[0] = index_line_map.size() - 1;
}
for (size_t i = 0; i < sel_rows.size(); i++) { for (int row : sel_rows) {
if (sel_rows[i] >= (int)index_line_map.size()) break; if (row >= (int)index_line_map.size()) break;
sel.insert(index_line_map[sel_rows[i]]); sel.insert(index_line_map[row]);
} }
SetSelectedSet(sel); SetSelectedSet(sel);

View File

@ -138,11 +138,10 @@ class DataBlockCache {
if (mb.blocks.empty()) if (mb.blocks.empty())
return; return;
for (size_t bi = 0; bi < mb.blocks.size(); ++bi) for (auto block : mb.blocks)
{ {
BlockT *b = mb.blocks[bi]; if (block)
if (b) factory.DisposeBlock(block);
factory.DisposeBlock(b);
} }
mb.blocks.clear(); mb.blocks.clear();
@ -205,10 +204,8 @@ public:
// Quick way out: get rid of everything // Quick way out: get rid of everything
if (max_size == 0) if (max_size == 0)
{ {
for (size_t mbi = 0; mbi < data.size(); ++mbi) for (auto& mb : data)
{ KillMacroBlock(mb);
KillMacroBlock(data[mbi]);
}
return; return;
} }

View File

@ -53,34 +53,32 @@ namespace CharSetDetect {
wxString GetEncoding(wxString const& filename) { wxString GetEncoding(wxString const& filename) {
agi::charset::CharsetListDetected list; agi::charset::CharsetListDetected list;
agi::charset::CharsetListDetected::const_iterator i_lst;
try { try {
agi::charset::DetectAll(STD_STR(filename), list); agi::charset::DetectAll(from_wx(filename), list);
} catch (const agi::charset::UnknownCharset&) { } catch (const agi::charset::UnknownCharset&) {
/// @todo If the charset is unknown we need to display a complete list of character sets. /// @todo If the charset is unknown we need to display a complete list of character sets.
} }
if (list.size() > 1) { if (list.size() == 1) {
// Get choice from user auto charset = list.begin();
wxArrayString choices; LOG_I("charset/file") << filename << " (" << charset->second << ")";
return charset->second;
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);
} }
i_lst = list.begin(); wxArrayString choices;
LOG_I("charset/file") << filename << " (" << i_lst->second << ")"; std::string log_choice;
return i_lst->second;
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];
} }
} }

View File

@ -220,9 +220,9 @@ struct audio_save_clip : public Command {
if (sel.empty()) return; if (sel.empty()) return;
AssTime start = INT_MAX, end = 0; AssTime start = INT_MAX, end = 0;
for (SubtitleSelection::iterator it = sel.begin(); it != sel.end(); ++it) { for (auto line : sel) {
start = std::min(start, (*it)->Start); start = std::min(start, line->Start);
end = std::max(end, (*it)->End); end = std::max(end, line->End);
} }
c->audioController->SaveClip( c->audioController->SaveClip(

View File

@ -68,8 +68,8 @@ namespace cmd {
std::vector<std::string> get_registered_commands() { std::vector<std::string> get_registered_commands() {
std::vector<std::string> ret; std::vector<std::string> ret;
ret.reserve(cmd_map.size()); ret.reserve(cmd_map.size());
for (iterator it = cmd_map.begin(); it != cmd_map.end(); ++it) for (auto const& it : cmd_map)
ret.push_back(it->first); ret.push_back(it.first);
return ret; return ret;
} }
@ -110,9 +110,8 @@ namespace cmd {
} }
void clear() { void clear() {
for (std::map<std::string, Command*>::iterator it = cmd_map.begin(); it != cmd_map.end(); ++it) { for (auto& it : cmd_map)
delete it->second; delete it.second;
}
cmd_map.clear(); cmd_map.clear();
} }
} }

View File

@ -485,8 +485,8 @@ struct edit_find_replace : public Command {
static void copy_lines(agi::Context *c) { static void copy_lines(agi::Context *c) {
wxString data; wxString data;
SubtitleSelection sel = c->selectionController->GetSelectedSet(); SubtitleSelection sel = c->selectionController->GetSelectedSet();
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { for (auto& line : c->ass->Line) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it); AssDialogue *diag = dynamic_cast<AssDialogue*>(&line);
if (diag && sel.count(diag)) { if (diag && sel.count(diag)) {
if (!data.empty()) if (!data.empty())
data += "\r\n"; data += "\r\n";
@ -505,8 +505,8 @@ static void delete_lines(agi::Context *c, wxString const& commit_message) {
AssDialogue *new_active = 0; AssDialogue *new_active = 0;
bool hit_active = false; bool hit_active = false;
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { for (auto& line : c->ass->Line) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it); AssDialogue *diag = dynamic_cast<AssDialogue*>(&line);
if (!diag) continue; if (!diag) continue;
if (diag == active) { if (diag == active) {

View File

@ -71,8 +71,8 @@ namespace {
if (sel.size() < 2) return false; if (sel.size() < 2) return false;
size_t found = 0; size_t found = 0;
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { for (auto& line : c->ass->Line) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it); AssDialogue *diag = dynamic_cast<AssDialogue*>(&line);
if (!diag) continue; if (!diag) continue;
if (sel.count(diag)) { 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 target_start = std::max(0, c->videoController->TimeAtFrame(c->videoController->GetFrameN(), agi::vfr::START));
int shift_by = target_start - active_line->Start; int shift_by = target_start - active_line->Start;
for (SubtitleSelection::const_iterator it = sel.begin(); it != sel.end(); ++it) { for (auto line : sel) {
(*it)->Start = (*it)->Start + shift_by; line->Start = line->Start + shift_by;
(*it)->End = (*it)->End + shift_by; line->End = line->End + shift_by;
} }
c->ass->Commit(_("shift to frame"), AssFile::COMMIT_DIAG_TIME); 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 start = c->videoController->TimeAtFrame(c->videoController->GetFrameN(), agi::vfr::START);
int end = c->videoController->TimeAtFrame(c->videoController->GetFrameN(), agi::vfr::END); int end = c->videoController->TimeAtFrame(c->videoController->GetFrameN(), agi::vfr::END);
for (SubtitleSelection::const_iterator it = sel.begin(); it != sel.end(); ++it) { for (auto line : sel) {
if (set_start || (*it)->Start > start) if (set_start || line->Start > start)
(*it)->Start = start; line->Start = start;
if (!set_start || (*it)->End < end) if (!set_start || line->End < end)
(*it)->End = end; line->End = end;
} }
c->ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME); 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; if (!con->IsLoaded() || !con->KeyFramesLoaded()) return;
// Get frames // Get frames
wxArrayInt sel = c->subsGrid->GetSelection();
int curFrame = con->GetFrameN(); int curFrame = con->GetFrameN();
int prev = 0; int prev = 0;
int next = 0; int next = 0;
@ -229,13 +228,11 @@ struct time_snap_scene : public validate_video_loaded {
// Get times // Get times
int start_ms = con->TimeAtFrame(prev,agi::vfr::START); int start_ms = con->TimeAtFrame(prev,agi::vfr::START);
int end_ms = con->TimeAtFrame(next-1,agi::vfr::END); int end_ms = con->TimeAtFrame(next-1,agi::vfr::END);
AssDialogue *cur;
// Update rows // Update rows
for (size_t i=0;i<sel.Count();i++) { for (auto line : c->selectionController->GetSelectedSet()) {
cur = c->subsGrid->GetDialogue(sel[i]); line->Start = start_ms;
cur->Start = start_ms; line->End = end_ms;
cur->End = end_ms;
} }
// Commit // Commit

View File

@ -102,9 +102,8 @@ void DialogAttachments::UpdateList() {
listView->InsertColumn(2, _("Group"), wxLIST_FORMAT_LEFT, 100); listView->InsertColumn(2, _("Group"), wxLIST_FORMAT_LEFT, 100);
// Fill list // Fill list
for (entryIter cur = ass->Line.begin();cur != ass->Line.end();cur++) { for (auto& line : ass->Line) {
if (AssAttachment *attach = dynamic_cast<AssAttachment*>(&*cur)) { if (AssAttachment *attach = dynamic_cast<AssAttachment*>(&line)) {
// Add item
int row = listView->GetItemCount(); int row = listView->GetItemCount();
listView->InsertItem(row,attach->GetFileName(true)); listView->InsertItem(row,attach->GetFileName(true));
listView->SetItem(row,1,PrettySize(attach->GetSize())); listView->SetItem(row,1,PrettySize(attach->GetSize()));

View File

@ -199,16 +199,16 @@ void DialogAutomation::OnAdd(wxCommandEvent &)
wxArrayString fnames; wxArrayString fnames;
diag.GetPaths(fnames); diag.GetPaths(fnames);
for (size_t i = 0; i < fnames.size(); ++i) { for (auto const& fname : fnames) {
wxFileName fnpath(fnames[i]); wxFileName fnpath(fname);
OPT_SET("Path/Last/Automation")->SetString(STD_STR(fnpath.GetPath())); OPT_SET("Path/Last/Automation")->SetString(STD_STR(fnpath.GetPath()));
if (has_file(local_manager->GetScripts(), fnpath) || has_file(global_manager->GetScripts(), fnpath)) { 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; continue;
} }
local_manager->Add(Automation4::ScriptFactory::CreateFromFile(fnames[i], true)); local_manager->Add(Automation4::ScriptFactory::CreateFromFile(fname, true));
} }
} }

View File

@ -436,7 +436,7 @@ std::vector<agi::Color> ColorPickerRecent::Save() const
void ColorPickerRecent::AddColor(agi::Color color) void ColorPickerRecent::AddColor(agi::Color color)
{ {
std::vector<agi::Color>::iterator existing = find(colors.begin(), colors.end(), color); auto existing = find(colors.begin(), colors.end(), color);
if (existing != colors.end()) if (existing != colors.end())
rotate(colors.begin(), existing, existing + 1); rotate(colors.begin(), existing, existing + 1);
else { else {

View File

@ -117,9 +117,9 @@ class FontsCollectorThread : public wxThread {
int64_t total_size = 0; int64_t total_size = 0;
bool allOk = true; bool allOk = true;
for (std::vector<wxString>::iterator cur = paths.begin(); cur != paths.end(); ++cur) { for (wxString const& path : paths) {
int ret = 0; int ret = 0;
wxFileName cur_fn(*cur); wxFileName cur_fn(path);
total_size += cur_fn.GetSize().GetValue(); total_size += cur_fn.GetSize().GetValue();
switch (oper) { switch (oper) {
@ -139,12 +139,12 @@ class FontsCollectorThread : public wxThread {
} }
#endif #endif
else else
ret = wxCopyFile(*cur, dest, true); ret = wxCopyFile(path, dest, true);
} }
break; break;
case CopyToZip: { case CopyToZip: {
wxFFileInputStream in(*cur); wxFFileInputStream in(path);
if (!in.IsOk()) if (!in.IsOk())
ret = false; ret = false;
else { else {
@ -156,13 +156,13 @@ class FontsCollectorThread : public wxThread {
} }
if (ret == 1) if (ret == 1)
AppendText(wxString::Format(_("* Copied %s.\n"), *cur), 1); AppendText(wxString::Format(_("* Copied %s.\n"), path), 1);
else if (ret == 2) 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) else if (ret == 3)
AppendText(wxString::Format(_("* Symlinked %s.\n"), *cur), 1); AppendText(wxString::Format(_("* Symlinked %s.\n"), path), 1);
else { else {
AppendText(wxString::Format(_("* Failed to copy %s.\n"), *cur), 2); AppendText(wxString::Format(_("* Failed to copy %s.\n"), path), 2);
allOk = false; allOk = false;
} }
} }

View File

@ -240,9 +240,8 @@ void KaraokeLineMatchDisplay::OnPaint(wxPaintEvent &)
// Draw matched groups // Draw matched groups
int this_total_matchgroup_render_width = 0; int this_total_matchgroup_render_width = 0;
bool scroll_arrows_drawn = false; 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; int prev_x = next_x;
// Skip groups that would cause the input part to be too far right // Skip groups that would cause the input part to be too far right
@ -273,10 +272,8 @@ void KaraokeLineMatchDisplay::OnPaint(wxPaintEvent &)
// Matched source syllables // Matched source syllables
int syl_x = next_x; int syl_x = next_x;
for (size_t j = 0; j < grp.src.size(); ++j) for (auto const& syl : grp.src)
{ syl_x += DrawBoxedText(dc, syl.text, syl_x, y_line1);
syl_x += DrawBoxedText(dc, grp.src[j].text, syl_x, y_line1);
}
// Matched destination text // Matched destination text
{ {
@ -371,14 +368,11 @@ wxString KaraokeLineMatchDisplay::GetOutputLine() const
{ {
wxString res; 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; int duration = 0;
for (size_t j = 0; j < match.src.size(); ++j) for (auto const& syl : match.src)
{ duration += syl.duration;
duration += match.src[j].duration;
}
res = wxString::Format("%s{\\k%d}%s", res, duration / 10, match.dst); 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 // For the magic number 5, see big comment block above
int src_lookahead_max = (lookahead+1)*5; int src_lookahead_max = (lookahead+1)*5;
int src_lookahead_pos = 0; int src_lookahead_pos = 0;
for (std::deque<MatchSyllable>::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 // Check if we've gone too far ahead in the source
if (src_lookahead_pos++ >= src_lookahead_max) break; if (src_lookahead_pos++ >= src_lookahead_max) break;
// Otherwise look for a match // Otherwise look for a match
if (ss->text.StartsWith(matched_roma)) if (syl.text.StartsWith(matched_roma))
{ {
// Yay! Time to interpolate. // Yay! Time to interpolate.
// Special case: If the last source syllable before the matching one is // Special case: If the last source syllable before the matching one is
@ -725,9 +719,8 @@ END_EVENT_TABLE()
void DialogKanjiTimer::OnClose(wxCommandEvent &) { void DialogKanjiTimer::OnClose(wxCommandEvent &) {
OPT_SET("Tool/Kanji Timer/Interpolation")->SetBool(Interpolate->IsChecked()); OPT_SET("Tool/Kanji Timer/Interpolation")->SetBool(Interpolate->IsChecked());
for (size_t i = 0; i < LinesToChange.size(); ++i) { for (auto& line : LinesToChange)
LinesToChange[i].first->Text = LinesToChange[i].second; line.first->Text = line.second;
}
if (LinesToChange.size()) { if (LinesToChange.size()) {
subs->Commit(_("kanji timing"), AssFile::COMMIT_DIAG_TEXT); subs->Commit(_("kanji timing"), AssFile::COMMIT_DIAG_TEXT);

View File

@ -106,9 +106,9 @@ public:
} }
~DialogManager() { ~DialogManager() {
for (DialogMap::iterator it = created_dialogs.begin(); it != created_dialogs.end(); ++it) { for (auto const& it : created_dialogs) {
it->second->Unbind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this); it.second->Unbind(wxEVT_CLOSE_WINDOW, &DialogManager::OnClose, this);
it->second->Destroy(); it.second->Destroy();
} }
created_dialogs.clear(); created_dialogs.clear();
} }

View File

@ -144,8 +144,8 @@ void DialogProperties::AddProperty(wxSizer *sizer, wxString const& label, wxStri
void DialogProperties::OnOK(wxCommandEvent &) { void DialogProperties::OnOK(wxCommandEvent &) {
int count = 0; int count = 0;
for (size_t i = 0; i < properties.size(); ++i) for (auto const& prop : properties)
count += SetInfoIfDifferent(properties[i].first, properties[i].second->GetValue()); count += SetInfoIfDifferent(prop.first, prop.second->GetValue());
count += SetInfoIfDifferent("PlayResX", ResX->GetValue()); count += SetInfoIfDifferent("PlayResX", ResX->GetValue());
count += SetInfoIfDifferent("PlayResY", ResY->GetValue()); count += SetInfoIfDifferent("PlayResY", ResY->GetValue());

View File

@ -206,9 +206,9 @@ namespace {
diag->ParseAssTags(); diag->ParseAssTags();
diag->ProcessParameters(resample_tags, state); diag->ProcessParameters(resample_tags, state);
for (size_t i = 0; i < diag->Blocks.size(); ++i) { for (auto block : diag->Blocks) {
if (AssDialogueBlockDrawing *block = dynamic_cast<AssDialogueBlockDrawing*>(diag->Blocks[i])) if (AssDialogueBlockDrawing *drawing = dynamic_cast<AssDialogueBlockDrawing*>(block))
block->TransformCoords(state->margin[LEFT], state->margin[TOP], state->rx, state->ry); drawing->TransformCoords(state->margin[LEFT], state->margin[TOP], state->rx, state->ry);
} }
for (size_t i = 0; i < 3; ++i) for (size_t i = 0; i < 3; ++i)

View File

@ -379,8 +379,8 @@ void SearchReplaceEngine::ReplaceAll() {
bool inSel = affect == 1; bool inSel = affect == 1;
// Scan // Scan
for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it) { for (auto& line : context->ass->Line) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it); AssDialogue *diag = dynamic_cast<AssDialogue*>(&line);
if (!diag) continue; if (!diag) continue;
// Check if row is selected // Check if row is selected

View File

@ -113,8 +113,8 @@ static std::set<AssDialogue*> process(wxString match_text, bool match_case, int
std::function<bool (wxString)> pred = get_predicate(mode, &re, match_case, match_text); std::function<bool (wxString)> pred = get_predicate(mode, &re, match_case, match_text);
std::set<AssDialogue*> matches; std::set<AssDialogue*> matches;
for (entryIter it = ass->Line.begin(); it != ass->Line.end(); ++it) { for (auto& line : ass->Line) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it); AssDialogue *diag = dynamic_cast<AssDialogue*>(&line);
if (!diag) continue; if (!diag) continue;
if (diag->Comment && !comments) continue; if (diag->Comment && !comments) continue;
if (!diag->Comment && !dialogue) continue; if (!diag->Comment && !dialogue) continue;

View File

@ -308,8 +308,8 @@ void DialogShiftTimes::LoadHistory() {
json::Reader::Read(root, *file); json::Reader::Read(root, *file);
*history = root; *history = root;
for (json::Array::iterator it = history->begin(); it != history->end(); ++it) for (auto& history_entry : *history)
history_box->Append(get_history_string(*it)); history_box->Append(get_history_string(history_entry));
} }
catch (agi::FileSystemError const& e) { catch (agi::FileSystemError const& e) {
LOG_D("dialog_shift_times/load_history") << "Cannot load shift times history: " << e.GetChainedMessage(); 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; int block_start = 0;
json::Array shifted_blocks; json::Array shifted_blocks;
for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it) { for (auto& entry : context->ass->Line) {
AssDialogue *line = dynamic_cast<AssDialogue*>(&*it); AssDialogue *line = dynamic_cast<AssDialogue*>(&entry);
if (!line) continue; if (!line) continue;
++row_number; ++row_number;

View File

@ -251,10 +251,10 @@ bool DialogSpellChecker::CheckLine(AssDialogue *active_line, int start_pos, int
GetWordBoundaries(active_line->Text, results); GetWordBoundaries(active_line->Text, results);
int shift = 0; int shift = 0;
for (size_t j = 0; j < results.size(); ++j) { for (auto const& result : results) {
word_start = results[j].first + shift; word_start = result.first + shift;
if (word_start < start_pos) continue; 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); wxString word = active_line->Text.Mid(word_start, word_end - word_start);
if (auto_ignore.count(word) || spellchecker->CheckWord(from_wx(word))) continue; if (auto_ignore.count(word) || spellchecker->CheckWord(from_wx(word))) continue;

View File

@ -87,8 +87,8 @@ class StyleRenamer {
found_any = false; found_any = false;
do_replace = replace; do_replace = replace;
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { for (auto& line : c->ass->Line) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it); AssDialogue *diag = dynamic_cast<AssDialogue*>(&line);
if (!diag) continue; if (!diag) continue;
if (diag->Style == source_name) { if (diag->Style == source_name) {
@ -425,9 +425,9 @@ void DialogStyleEditor::Apply(bool apply, bool close) {
wxArrayString styles = store ? store->GetNames() : c->ass->GetStyles(); wxArrayString styles = store ? store->GetNames() : c->ass->GetStyles();
// Check if style name is unique // Check if style name is unique
for (unsigned int i=0;i<styles.Count();i++) { for (auto const& style_name : styles) {
if (newStyleName.CmpNoCase(styles[i]) == 0) { if (newStyleName.CmpNoCase(style_name) == 0) {
if ((store && store->GetStyle(styles[i]) != style) || (!store && c->ass->GetStyle(styles[i]) != style)) { 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); wxMessageBox("There is already a style with this name. Please choose another name.", "Style name conflict.", wxOK | wxICON_ERROR | wxCENTER);
return; return;
} }

View File

@ -274,8 +274,8 @@ void DialogStyleManager::LoadCurrentStyles(int commit_type) {
CurrentList->Clear(); CurrentList->Clear();
styleMap.clear(); styleMap.clear();
for (entryIter cur = c->ass->Line.begin(); cur != c->ass->Line.end(); ++cur) { for (auto& line : c->ass->Line) {
if (AssStyle *style = dynamic_cast<AssStyle*>(&*cur)) { if (AssStyle *style = dynamic_cast<AssStyle*>(&line)) {
CurrentList->Append(style->name); CurrentList->Append(style->name);
styleMap.push_back(style); styleMap.push_back(style);
} }
@ -306,8 +306,8 @@ void DialogStyleManager::UpdateStorage() {
Store.Save(); Store.Save();
StorageList->Clear(); StorageList->Clear();
for (AssStyleStorage::iterator cur = Store.begin(); cur != Store.end(); ++cur) for (auto style : Store)
StorageList->Append((*cur)->name); StorageList->Append(style->name);
UpdateButtons(); UpdateButtons();
} }
@ -360,9 +360,9 @@ void DialogStyleManager::OnCatalogNew() {
// Remove bad characters from the name // Remove bad characters from the name
wxString badchars = wxFileName::GetForbiddenChars(wxPATH_DOS); wxString badchars = wxFileName::GetForbiddenChars(wxPATH_DOS);
int badchars_removed = 0; int badchars_removed = 0;
for (size_t i = 0; i < name.size(); ++i) { for (wxUniCharRef chr : name) {
if (badchars.find(name[i]) != badchars.npos) { if (badchars.find(chr) != badchars.npos) {
name[i] = '_'; chr = '_';
++badchars_removed; ++badchars_removed;
} }
} }
@ -420,8 +420,8 @@ void DialogStyleManager::OnCopyToStorage() {
} }
UpdateStorage(); UpdateStorage();
for (std::list<wxString>::iterator name = copied.begin(); name != copied.end(); ++name) for (auto const& style_name : copied)
StorageList->SetStringSelection(*name, true); StorageList->SetStringSelection(style_name, true);
UpdateButtons(); UpdateButtons();
} }
@ -434,7 +434,7 @@ void DialogStyleManager::OnCopyToCurrent() {
wxString styleName = StorageList->GetString(selections[i]); wxString styleName = StorageList->GetString(selections[i]);
bool addStyle = true; bool addStyle = true;
for (std::vector<AssStyle *>::iterator style = styleMap.begin(); style != styleMap.end(); ++style) { for (auto style = styleMap.begin(); style != styleMap.end(); ++style) {
if ((*style)->name.CmpNoCase(styleName) == 0) { if ((*style)->name.CmpNoCase(styleName) == 0) {
addStyle = false; 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)) { 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); c->ass->Commit(_("style copy"), AssFile::COMMIT_STYLES);
CurrentList->DeselectAll(); CurrentList->DeselectAll();
for (std::list<wxString>::iterator name = copied.begin(); name != copied.end(); ++name) for (auto const& style_name : copied)
CurrentList->SetStringSelection(*name, true); CurrentList->SetStringSelection(style_name, true);
UpdateButtons(); UpdateButtons();
} }
@ -603,12 +603,12 @@ void DialogStyleManager::OnCurrentImport() {
bool modified = false; bool modified = false;
// Loop through selection // 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 // 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) { if (test != wxNOT_FOUND) {
int answer = wxMessageBox( 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"), _("Style name collision"),
wxYES_NO); wxYES_NO);
if (answer == wxYES) { if (answer == wxYES) {
@ -617,7 +617,7 @@ void DialogStyleManager::OnCurrentImport() {
// The result of GetString is used rather than the name // The result of GetString is used rather than the name
// itself to deal with that AssFile::GetStyle is // itself to deal with that AssFile::GetStyle is
// case-sensitive, but style names are case insensitive // 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; continue;
} }
@ -625,7 +625,7 @@ void DialogStyleManager::OnCurrentImport() {
// Copy // Copy
modified = true; modified = true;
AssStyle *tempStyle = new AssStyle; AssStyle *tempStyle = new AssStyle;
*tempStyle = *temp.GetStyle(styles[selections[i]]); *tempStyle = *temp.GetStyle(styles[sel]);
c->ass->InsertStyle(tempStyle); c->ass->InsertStyle(tempStyle);
} }

View File

@ -247,8 +247,8 @@ void DialogTranslation::UpdateDisplay() {
original_text->SetReadOnly(false); original_text->SetReadOnly(false);
original_text->ClearAll(); original_text->ClearAll();
for (size_t i = 0; i < active_line->Blocks.size(); ++i) { size_t i = 0;
AssDialogueBlock *block = active_line->Blocks[i]; for (auto block : active_line->Blocks) {
if (block->GetType() == BLOCK_PLAIN) { if (block->GetType() == BLOCK_PLAIN) {
int cur_size = original_text->GetReverseUnicodePosition(original_text->GetLength()); int cur_size = original_text->GetReverseUnicodePosition(original_text->GetLength());
original_text->AppendText(block->GetText()); original_text->AppendText(block->GetText());
@ -259,6 +259,7 @@ void DialogTranslation::UpdateDisplay() {
} }
else if (block->GetType() == BLOCK_OVERRIDE) else if (block->GetType() == BLOCK_OVERRIDE)
original_text->AppendText("{" + block->GetText() + "}"); original_text->AppendText("{" + block->GetText() + "}");
++i;
} }
original_text->SetReadOnly(true); original_text->SetReadOnly(true);

View File

@ -53,11 +53,10 @@ void AssFixStylesFilter::ProcessSubs(AssFile *subs, wxWindow *) {
for_each(styles.begin(), styles.end(), std::mem_fun_ref(&wxString::MakeLower)); for_each(styles.begin(), styles.end(), std::mem_fun_ref(&wxString::MakeLower));
styles.Sort(); styles.Sort();
for (entryIter cur=subs->Line.begin();cur!=subs->Line.end();cur++) { for (auto& line : subs->Line) {
if (AssDialogue *diag = dynamic_cast<AssDialogue*>(&*cur)) { if (AssDialogue *diag = dynamic_cast<AssDialogue*>(&line)) {
if (!std::binary_search(styles.begin(), styles.end(), diag->Style.Lower())) { if (!std::binary_search(styles.begin(), styles.end(), diag->Style.Lower()))
diag->Style = "Default"; diag->Style = "Default";
}
} }
} }
} }

View File

@ -208,24 +208,23 @@ void AssTransformFramerateFilter::TransformTimeTags(wxString name,int n,AssOverr
void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) { void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) {
if (!Input->IsLoaded() || !Output->IsLoaded()) return; if (!Input->IsLoaded() || !Output->IsLoaded()) return;
for (entryIter cur=subs->Line.begin();cur!=subs->Line.end();cur++) { for (auto& entry : subs->Line) {
AssDialogue *curDialogue = dynamic_cast<AssDialogue*>(&*cur); AssDialogue *curDialogue = dynamic_cast<AssDialogue*>(&entry);
if (!curDialogue) continue;
if (curDialogue) { line = curDialogue;
line = curDialogue; newK = 0;
newK = 0; oldK = 0;
oldK = 0; newStart = trunc_cs(ConvertTime(curDialogue->Start));
newStart = trunc_cs(ConvertTime(curDialogue->Start)); newEnd = trunc_cs(ConvertTime(curDialogue->End) + 9);
newEnd = trunc_cs(ConvertTime(curDialogue->End) + 9);
// Process stuff // Process stuff
curDialogue->ParseAssTags(); curDialogue->ParseAssTags();
curDialogue->ProcessParameters(TransformTimeTags, this); curDialogue->ProcessParameters(TransformTimeTags, this);
curDialogue->Start = newStart; curDialogue->Start = newStart;
curDialogue->End = newEnd; curDialogue->End = newEnd;
curDialogue->UpdateText(); curDialogue->UpdateText();
curDialogue->ClearBlocks(); curDialogue->ClearBlocks();
}
} }
} }

View File

@ -58,9 +58,8 @@ protected:
classes->insert(std::make_pair(name, std::make_pair(hide, function))); classes->insert(std::make_pair(name, std::make_pair(hide, function)));
} }
else { else {
for (size_t i = 0; i < subtypes.size(); i++) { for (auto const& subtype : subtypes)
classes->insert(std::make_pair(name + '/' + subtypes[i], std::make_pair(hide, function))); classes->insert(std::make_pair(name + '/' + subtype, std::make_pair(hide, function)));
}
} }
} }
@ -81,11 +80,11 @@ public:
if (!classes) return list; if (!classes) return list;
std::string cmp; std::string cmp;
std::transform(favourite.begin(), favourite.end(), favourite.begin(), ::tolower); 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(); cmp.clear();
std::transform(cur->first.begin(), cur->first.end(), std::back_inserter(cmp), ::tolower); std::transform(cls.first.begin(), cls.first.end(), std::back_inserter(cmp), ::tolower);
if (cmp == favourite) list.insert(list.begin(), cur->first); if (cmp == favourite) list.insert(list.begin(), cls.first);
else if (!cur->second.first) list.push_back(cur->first); else if (!cls.second.first) list.push_back(cls.first);
} }
return list; return list;
} }

View File

@ -157,9 +157,9 @@ int FFmpegSourceProvider::AskForTrackSelection(const std::map<int,wxString> &Tra
std::vector<int> TrackNumbers; std::vector<int> TrackNumbers;
wxArrayString Choices; wxArrayString Choices;
for (std::map<int,wxString>::const_iterator i = TrackList.begin(); i != TrackList.end(); i++) { for (auto const& track : TrackList) {
Choices.Add(wxString::Format(_("Track %02d: %s"), i->first, i->second)); Choices.Add(wxString::Format(_("Track %02d: %s"), track.first, track.second));
TrackNumbers.push_back(i->first); TrackNumbers.push_back(track.first);
} }
int Choice = wxGetSingleChoiceIndex( int Choice = wxGetSingleChoiceIndex(

View File

@ -54,10 +54,9 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
bool overriden = false; bool overriden = false;
for (size_t i = 0; i < blocks.size(); ++i) { for (auto block : blocks) {
if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride *>(blocks[i])) { if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride *>(block)) {
for (size_t j = 0; j < ovr->Tags.size(); ++j) { for (auto tag : ovr->Tags) {
AssOverrideTag *tag = ovr->Tags[j];
wxString name = tag->Name; wxString name = tag->Name;
if (name == "\\r") { if (name == "\\r") {
@ -78,7 +77,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
} }
} }
} }
else if (AssDialogueBlockPlain *txt = dynamic_cast<AssDialogueBlockPlain *>(blocks[i])) { else if (AssDialogueBlockPlain *txt = dynamic_cast<AssDialogueBlockPlain *>(block)) {
wxString text = txt->GetText(); wxString text = txt->GetText();
if (text.empty() || (text.size() >= 2 && text.StartsWith("{") && text.EndsWith("}"))) if (text.empty() || (text.size() >= 2 && text.StartsWith("{") && text.EndsWith("}")))
@ -136,14 +135,14 @@ void FontCollector::ProcessChunk(std::pair<StyleInfo, UsageData> const& style) {
void FontCollector::PrintUsage(UsageData const& data) { void FontCollector::PrintUsage(UsageData const& data) {
if (data.styles.size()) { if (data.styles.size()) {
status_callback(wxString::Format(_("Used in styles:\n")), 2); status_callback(wxString::Format(_("Used in styles:\n")), 2);
for (std::set<wxString>::const_iterator it = data.styles.begin(); it != data.styles.end(); ++it) for (auto const& style : data.styles)
status_callback(wxString::Format(" - %s\n", *it), 2); status_callback(wxString::Format(" - %s\n", style), 2);
} }
if (data.lines.size()) { if (data.lines.size()) {
status_callback(wxString::Format(_("Used on lines:")), 2); status_callback(wxString::Format(_("Used on lines:")), 2);
for (std::set<int>::const_iterator it = data.lines.begin(); it != data.lines.end(); ++it) for (int line : data.lines)
status_callback(wxString::Format(" %d", *it), 2); status_callback(wxString::Format(" %d", line), 2);
status_callback("\n", 2); status_callback("\n", 2);
} }
status_callback("\n", 2); status_callback("\n", 2);
@ -156,15 +155,15 @@ std::vector<wxString> FontCollector::GetFontPaths(const AssFile *file) {
status_callback(_("Parsing file\n"), 0); status_callback(_("Parsing file\n"), 0);
int index = 0; int index = 0;
for (constEntryIter cur = file->Line.begin(); cur != file->Line.end(); ++cur) { for (auto const& line : file->Line) {
if (const AssStyle *style = dynamic_cast<const AssStyle*>(&*cur)) { if (const AssStyle *style = dynamic_cast<const AssStyle*>(&line)) {
StyleInfo &info = styles[style->name]; StyleInfo &info = styles[style->name];
info.facename = style->font; info.facename = style->font;
info.bold = style->bold; info.bold = style->bold;
info.italic = style->italic; info.italic = style->italic;
used_styles[info].styles.insert(style->name); used_styles[info].styles.insert(style->name);
} }
else if (const AssDialogue *diag = dynamic_cast<const AssDialogue*>(&*cur)) else if (const AssDialogue *diag = dynamic_cast<const AssDialogue*>(&line))
ProcessDialogueLine(diag, ++index); ProcessDialogueLine(diag, ++index);
} }

View File

@ -205,9 +205,9 @@ FontFileLister::CollectionResult FontConfigFontFileLister::GetFontPaths(wxString
FcCharSet *charset; FcCharSet *charset;
if (FcPatternGetCharSet(rpat, FC_CHARSET, 0, &charset) == FcResultMatch) { if (FcPatternGetCharSet(rpat, FC_CHARSET, 0, &charset) == FcResultMatch) {
for (std::set<wxUniChar>::const_iterator it = characters.begin(); it != characters.end(); ++it) { for (wxUniChar chr : characters) {
if (!FcCharSetHasChar(charset, *it)) if (!FcCharSetHasChar(charset, chr))
ret.missing += *it; ret.missing += chr;
} }
} }

View File

@ -146,8 +146,7 @@ static void get_files_to_load(wxArrayString const& list, wxString &subs, wxStrin
}; };
// Scan list // Scan list
for (size_t i = 0; i < list.size(); ++i) { for (wxFileName file : list) {
wxFileName file(list[i]);
if (file.IsRelative()) file.MakeAbsolute(); if (file.IsRelative()) file.MakeAbsolute();
if (!file.FileExists()) continue; if (!file.FileExists()) continue;

View File

@ -156,13 +156,10 @@ void OpenGLText::Print(const wxString &text,int x,int y) {
} }
void OpenGLText::DrawString(const wxString &text,int x,int y) { void OpenGLText::DrawString(const wxString &text,int x,int y) {
size_t len = text.Length();
lineHeight = 0; lineHeight = 0;
int dx=x,dy=y; int dx=x,dy=y;
for (size_t i=0;i<len;i++) { for (int curChar : text) {
int curChar = text[i];
// Handle carriage returns // Handle carriage returns
if (curChar == '\n') { if (curChar == '\n') {
dx = x; dx = x;
@ -180,17 +177,13 @@ void OpenGLText::DrawString(const wxString &text,int x,int y) {
} }
void OpenGLText::GetExtent(wxString const& text, int &w, int &h) { void OpenGLText::GetExtent(wxString const& text, int &w, int &h) {
size_t len = text.Length();
lineHeight = 0; lineHeight = 0;
int dx=0,dy=0; int dx=0,dy=0;
w = 0; w = 0;
h = 0; h = 0;
// Simulate drawing of string // Simulate drawing of string
for (size_t i=0;i<len;i++) { for (int curChar : text) {
// Get current character
int curChar = text[i];
// Handle carriage returns // Handle carriage returns
if (curChar == '\n') { if (curChar == '\n') {
if (dx > w) w = dx; if (dx > w) w = dx;
@ -224,8 +217,8 @@ OpenGLTextGlyph const& OpenGLText::CreateGlyph(int n) {
// Insert into some texture // Insert into some texture
bool ok = false; bool ok = false;
for (unsigned int i=0;i<textures.size();i++) { for (auto texture : textures) {
if (textures[i]->TryToInsert(glyph)) { if (texture->TryToInsert(glyph)) {
ok = true; ok = true;
break; break;
} }
@ -239,9 +232,6 @@ OpenGLTextGlyph const& OpenGLText::CreateGlyph(int n) {
return glyph; return glyph;
} }
/// @brief Texture constructor
/// @param w
/// @param h
OpenGLTextTexture::OpenGLTextTexture(OpenGLTextGlyph &glyph) { OpenGLTextTexture::OpenGLTextTexture(OpenGLTextGlyph &glyph) {
x = y = nextY = 0; x = y = nextY = 0;
width = std::max(SmallestPowerOf2(glyph.w), 64); width = std::max(SmallestPowerOf2(glyph.w), 64);

View File

@ -101,9 +101,9 @@ namespace {
name_map[renamed_commands[i][0]] = renamed_commands[i][1]; name_map[renamed_commands[i][0]] = renamed_commands[i][1];
bool renamed_any = false; bool renamed_any = false;
agi::hotkey::Hotkey::HotkeyMap hk_map = hotkey::inst->GetHotkeyMap(); auto hk_map = hotkey::inst->GetHotkeyMap();
for (agi::hotkey::Hotkey::HotkeyMap::iterator it = hk_map.begin(); it != hk_map.end(); ) { for (auto it = hk_map.begin(); it != hk_map.end(); ) {
std::map<std::string, const char *>::iterator ren = name_map.find(it->first); auto ren = name_map.find(it->first);
if (ren != name_map.end()) { if (ren != name_map.end()) {
hk_map.insert(make_pair(std::string(ren->second), hk_map.insert(make_pair(std::string(ren->second),
agi::hotkey::Combo(it->second.Context(), ren->second, it->second.Get()))); agi::hotkey::Combo(it->second.Context(), ren->second, it->second.Get())));

View File

@ -117,8 +117,7 @@ public:
wxArrayString toks = wxSplit(variant.GetString(), '-'); wxArrayString toks = wxSplit(variant.GetString(), '-');
std::vector<std::string> keys; std::vector<std::string> keys;
keys.resize(toks.size()); keys.resize(toks.size());
for (size_t i = 0; i < toks.size(); ++i) transform(toks.begin(), toks.end(), back_inserter(keys), (std::string(*)(wxString const&))&from_wx);
keys[i] = STD_STR(toks[i]);
combo = Combo(combo.Context(), combo.CmdName(), keys); combo = Combo(combo.Context(), combo.CmdName(), keys);
cmd_str = combo.Str(); cmd_str = combo.Str();
return true; return true;
@ -155,7 +154,7 @@ public:
} }
void Delete(wxDataViewItem const& item) { void Delete(wxDataViewItem const& item) {
for (std::list<HotkeyModelCombo>::iterator it = children.begin(); it != children.end(); ++it) { for (auto it = children.begin(); it != children.end(); ++it) {
if (&*it == item.GetID()) { if (&*it == item.GetID()) {
model->ItemDeleted(wxDataViewItem(this), wxDataViewItem((void*)&*it)); model->ItemDeleted(wxDataViewItem(this), wxDataViewItem((void*)&*it));
children.erase(it); children.erase(it);
@ -165,30 +164,30 @@ public:
} }
void Apply(Hotkey::HotkeyMap *hk_map) { void Apply(Hotkey::HotkeyMap *hk_map) {
for_each(children.begin(), children.end(), for (auto& combo : children)
bind(&HotkeyModelCombo::Apply, std::placeholders::_1, hk_map)); combo.Apply(hk_map);
} }
void SetFilter(wxRegEx const& new_filter) { void SetFilter(wxRegEx const& new_filter) {
std::set<HotkeyModelCombo*> old_visible; std::set<HotkeyModelCombo*> old_visible;
for (size_t i = 0; i < visible_items.size(); ++i) for (auto item : visible_items)
old_visible.insert(static_cast<HotkeyModelCombo*>(visible_items[i].GetID())); old_visible.insert(static_cast<HotkeyModelCombo*>(item.GetID()));
visible_items.clear(); visible_items.clear();
wxDataViewItemArray added; wxDataViewItemArray added;
wxDataViewItemArray removed; wxDataViewItemArray removed;
for (std::list<HotkeyModelCombo>::iterator it = children.begin(); it != children.end(); ++it) { for (auto& combo : children) {
bool was_visible = old_visible.count(&*it) > 0; bool was_visible = old_visible.count(&combo) > 0;
bool is_visible = it->IsVisible(new_filter); bool is_visible = combo.IsVisible(new_filter);
if (is_visible) if (is_visible)
visible_items.push_back(wxDataViewItem(&*it)); visible_items.push_back(wxDataViewItem(&combo));
if (was_visible && !is_visible) if (was_visible && !is_visible)
removed.push_back(wxDataViewItem(&*it)); removed.push_back(wxDataViewItem(&combo));
if (is_visible && !was_visible) if (is_visible && !was_visible)
added.push_back(wxDataViewItem(&*it)); added.push_back(wxDataViewItem(&combo));
} }
if (!added.empty()) if (!added.empty())
@ -222,10 +221,10 @@ public:
Hotkey::HotkeyMap const& hk_map = hotkey::inst->GetHotkeyMap(); Hotkey::HotkeyMap const& hk_map = hotkey::inst->GetHotkeyMap();
std::map<std::string, HotkeyModelCategory*> cat_map; std::map<std::string, HotkeyModelCategory*> cat_map;
for (Hotkey::HotkeyMap::const_iterator it = hk_map.begin(); it != hk_map.end(); ++it) { for (auto const& category : hk_map) {
std::string cat_name = it->second.Context(); std::string cat_name = category.second.Context();
HotkeyModelCategory *cat; HotkeyModelCategory *cat;
std::map<std::string, HotkeyModelCategory*>::iterator cat_it = cat_map.find(cat_name); auto cat_it = cat_map.find(cat_name);
if (cat_it != cat_map.end()) if (cat_it != cat_map.end())
cat = cat_it->second; cat = cat_it->second;
else { else {
@ -233,7 +232,7 @@ public:
cat = cat_map[cat_name] = &categories.back(); 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 { unsigned int GetChildren(wxDataViewItemArray &out) const {
out.reserve(categories.size()); out.reserve(categories.size());
for (std::list<HotkeyModelCategory>::const_iterator it = categories.begin(); it != categories.end(); ++it) for (auto const& category : categories)
out.push_back(wxDataViewItem((void*)&*it)); out.push_back(wxDataViewItem((void*)&category));
return out.size(); return out.size();
} }
}; };

View File

@ -255,9 +255,8 @@ bool AegisubApp::OnInit() {
// Get parameter subs // Get parameter subs
StartupLog("Parse command line"); StartupLog("Parse command line");
wxArrayString subs; wxArrayString subs;
for (int i=1;i<argc;i++) { for (int i = 1; i < argc; ++i)
subs.Add(argv[i]); subs.push_back(argv[i]);
}
// Open main frame // Open main frame
StartupLog("Create main window"); StartupLog("Create main window");
@ -475,12 +474,7 @@ int AegisubApp::OnRun() {
file << std::endl << timeStr.mb_str(csConvLocal); file << std::endl << timeStr.mb_str(csConvLocal);
file << "\nVER - " << GetAegisubLongVersionString(); file << "\nVER - " << GetAegisubLongVersionString();
file << "\nEXC - Aegisub has crashed with unhandled exception \"" << error.mb_str(csConvLocal) <<"\".\n"; file << "\nEXC - Aegisub has crashed with unhandled exception \"" << error.mb_str(csConvLocal) <<"\".\n";
int formatLen = timeStr.Length(); file << wxString('-', timeStr.size());
char dashes[1024];
int i = 0;
for (i=0;i<formatLen;i++) dashes[i] = '-';
dashes[i] = 0;
file << dashes;
file << "\n"; file << "\n";
file.close(); file.close();
} }

View File

@ -98,10 +98,7 @@ public:
} }
int i = 0; int i = 0;
for (agi::MRUManager::MRUListMap::const_iterator it = mru->begin(); for (auto it = mru->begin(); it != mru->end(); ++it, ++i) {
it != mru->end();
++it, ++i)
{
items[i]->SetItemLabel(wxString::Format("%s%d %s", items[i]->SetItemLabel(wxString::Format("%s%d %s",
i <= 9 ? "&" : "", i + 1, i <= 9 ? "&" : "", i + 1,
wxFileName(lagi_wxString(*it)).GetFullName())); wxFileName(lagi_wxString(*it)).GetFullName()));
@ -209,8 +206,7 @@ public:
/// Unregister a dynamic menu item /// Unregister a dynamic menu item
void Remove(wxMenuItem *item) { void Remove(wxMenuItem *item) {
std::deque<std::pair<std::string, wxMenuItem*> >::iterator it = auto it = find_if(dynamic_items.begin(), dynamic_items.end(), menu_item_cmp(item));
find_if(dynamic_items.begin(), dynamic_items.end(), menu_item_cmp(item));
if (it != dynamic_items.end()) if (it != dynamic_items.end())
dynamic_items.erase(it); dynamic_items.erase(it);
it = find_if(static_items.begin(), static_items.end(), menu_item_cmp(item)); 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); menu_items const& items = get_menu(name);
std::auto_ptr<CommandMenuBar> menu(new CommandMenuBar(c)); std::auto_ptr<CommandMenuBar> 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; std::string submenu, disp;
read_entry(*it, "submenu", &submenu); read_entry(item, "submenu", &submenu);
read_entry(*it, "text", &disp); read_entry(item, "text", &disp);
if (!submenu.empty()) { 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 { else {
read_entry(*it, "special", &submenu); read_entry(item, "special", &submenu);
if (submenu == "automation") if (submenu == "automation")
menu->Append(new AutomationMenu(c, &menu->cm), _(lagi_wxString(disp))); menu->Append(new AutomationMenu(c, &menu->cm), _(to_wx(disp)));
} }
} }

View File

@ -133,8 +133,8 @@ static void read_subtitles(agi::ProgressSink *ps, MatroskaFile *file, MkvStdIO *
delete[] readBuf; delete[] readBuf;
// Insert into file // Insert into file
for (std::map<int, wxString>::iterator it = subList.begin(); it != subList.end(); ++it) { for (auto order_value_pair : subList) {
parser->AddLine(it->second); parser->AddLine(order_value_pair.second);
} }
} }

View File

@ -449,8 +449,8 @@ void Interface_Hotkeys::OnUpdateFilter(wxCommandEvent&) {
if (!quick_search->GetValue().empty()) { if (!quick_search->GetValue().empty()) {
wxDataViewItemArray contexts; wxDataViewItemArray contexts;
model->GetChildren(wxDataViewItem(0), contexts); model->GetChildren(wxDataViewItem(0), contexts);
for (size_t i = 0; i < contexts.size(); ++i) for (auto const& context : contexts)
dvc->Expand(contexts[i]); dvc->Expand(context);
} }
} }
@ -635,14 +635,14 @@ void Preferences::OnOK(wxCommandEvent &event) {
} }
void Preferences::OnApply(wxCommandEvent &) { void Preferences::OnApply(wxCommandEvent &) {
for (std::map<std::string, agi::OptionValue*>::iterator cur = pending_changes.begin(); cur != pending_changes.end(); ++cur) { for (auto const& change : pending_changes) {
OPT_SET(cur->first)->Set(cur->second); OPT_SET(change.first)->Set(change.second);
delete cur->second; delete change.second;
} }
pending_changes.clear(); pending_changes.clear();
for (std::deque<Thunk>::iterator it = pending_callbacks.begin(); it != pending_callbacks.end(); ++it) for (auto const& thunk : pending_callbacks)
(*it)(); thunk();
pending_callbacks.clear(); pending_callbacks.clear();
applyButton->Enable(false); 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)) if (wxYES != wxMessageBox(_("Are you sure that you want to restore the defaults? All your settings will be overridden."), _("Restore defaults?"), wxYES_NO))
return; return;
for (std::deque<std::string>::iterator it = option_names.begin(); it != option_names.end(); ++it) { for (auto const& opt_name : option_names) {
agi::OptionValue *opt = OPT_SET(*it); agi::OptionValue *opt = OPT_SET(opt_name);
if (!opt->IsDefault()) if (!opt->IsDefault())
opt->Reset(); opt->Reset();
} }
@ -719,7 +719,6 @@ Preferences::Preferences(wxWindow *parent): wxDialog(parent, -1, _("Preferences"
} }
Preferences::~Preferences() { Preferences::~Preferences() {
for (std::map<std::string, agi::OptionValue*>::iterator cur = pending_changes.begin(); cur != pending_changes.end(); ++cur) { for (auto& change : pending_changes)
delete cur->second; delete change.second;
}
} }

View File

@ -88,10 +88,10 @@ void ScintillaTextCtrl::GetBoundsOfWordAtPosition(int pos,int &start,int &end) {
GetWordBoundaries(GetText(), results); GetWordBoundaries(GetText(), results);
// Get boundaries // Get boundaries
for (size_t i = 0; i < results.size(); i++) { for (auto const& result : results) {
if (results[i].first <= pos && results[i].second >= pos) { if (result.first <= pos && result.second >= pos) {
start = results[i].first; start = result.first;
end = results[i].second; end = result.second;
return; return;
} }
} }

View File

@ -48,14 +48,14 @@ agi::SpellChecker *SpellCheckerFactory::GetSpellChecker() {
// Get provider // Get provider
wxString error; wxString error;
for (unsigned int i=0;i<list.size();i++) { for (auto const& name : list) {
try { try {
agi::SpellChecker *checker = Create(list[i]); agi::SpellChecker *checker = Create(name);
if (checker) return checker; if (checker) return checker;
} }
catch (wxString const& err) { error += list[i] + " factory: " + err + "\n"; } catch (wxString const& err) { error += name + " factory: " + err + "\n"; }
catch (const char *err) { error += list[i] + " factory: " + wxString(err) + "\n"; } catch (const char *err) { error += name + " factory: " + wxString(err) + "\n"; }
catch (...) { error += list[i] + " factory: Unknown error\n"; } catch (...) { error += name + " factory: Unknown error\n"; }
} }
throw error; throw error;

View File

@ -315,8 +315,8 @@ void SubsEditBox::PopulateList(wxComboBox *combo, wxString AssDialogue::*field)
wxEventBlocker blocker(this); wxEventBlocker blocker(this);
std::set<wxString> values; std::set<wxString> values;
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { for (auto& line : c->ass->Line) {
if (AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it)) if (AssDialogue *diag = dynamic_cast<AssDialogue*>(&line))
values.insert(diag->*field); values.insert(diag->*field);
} }
values.erase(""); values.erase("");
@ -412,9 +412,7 @@ void SubsEditBox::CommitText(wxString const& desc) {
} }
void SubsEditBox::CommitTimes(TimeField field) { void SubsEditBox::CommitTimes(TimeField field) {
for (SubtitleSelection::iterator cur = sel.begin(); cur != sel.end(); ++cur) { for (AssDialogue *d : sel) {
AssDialogue *d = *cur;
if (!initialTimes.count(d)) if (!initialTimes.count(d))
initialTimes[d] = std::make_pair(d->Start, d->End); initialTimes[d] = std::make_pair(d->Start, d->End);

View File

@ -281,11 +281,9 @@ void SubsTextEditCtrl::UpdateStyle() {
AssDialogue *diag = context ? context->selectionController->GetActiveLine() : 0; AssDialogue *diag = context ? context->selectionController->GetActiveLine() : 0;
bool template_line = diag && diag->Comment && diag->Effect.Lower().StartsWith("template"); bool template_line = diag && diag->Comment && diag->Effect.Lower().StartsWith("template");
std::vector<agi::ass::DialogueToken> tokens = agi::ass::TokenizeDialogueBody(text); auto tokens = agi::ass::TokenizeDialogueBody(text);
std::vector<agi::ass::DialogueToken> style_ranges = agi::ass::SyntaxHighlight(text, tokens, template_line, spellchecker.get()); for (auto const& style_range : agi::ass::SyntaxHighlight(text, tokens, template_line, spellchecker.get()))
for (size_t i = 0; i < style_ranges.size(); ++i) { SetStyling(style_range.length, style_range.type);
SetStyling(style_ranges[i].length, style_ranges[i].type);
}
} }
/// @brief Update call tip /// @brief Update call tip
@ -611,32 +609,32 @@ void SubsTextEditCtrl::AddThesaurusEntries(wxMenu &menu) {
if (!thesaurus) if (!thesaurus)
thesaurus.reset(new Thesaurus); thesaurus.reset(new Thesaurus);
std::vector<Thesaurus::Entry> result; std::vector<Thesaurus::Entry> results;
thesaurus->Lookup(currentWord, &result); thesaurus->Lookup(currentWord, &results);
thesSugs.clear(); thesSugs.clear();
if (result.size()) { if (results.size()) {
wxMenu *thesMenu = new wxMenu; wxMenu *thesMenu = new wxMenu;
int curThesEntry = 0; int curThesEntry = 0;
for (size_t i = 0; i < result.size(); ++i) { for (auto const& result : results) {
// Single word, insert directly // Single word, insert directly
if (result[i].second.size() == 1) { if (result.second.size() == 1) {
thesMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, lagi_wxString(result[i].first)); thesMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, lagi_wxString(result.first));
thesSugs.push_back(result[i].first); thesSugs.push_back(result.first);
++curThesEntry; ++curThesEntry;
} }
// Multiple, create submenu // Multiple, create submenu
else { else {
wxMenu *subMenu = new wxMenu; wxMenu *subMenu = new wxMenu;
for (size_t j = 0; j < result[i].second.size(); ++j) { for (auto const& sug : result.second) {
subMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, lagi_wxString(result[i].second[j])); subMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, to_wx(sug));
thesSugs.push_back(result[i].second[j]); thesSugs.push_back(sug);
++curThesEntry; ++curThesEntry;
} }
thesMenu->Append(-1, lagi_wxString(result[i].first), subMenu); thesMenu->Append(-1, to_wx(result.first), subMenu);
} }
} }

View File

@ -79,18 +79,18 @@ bool SubtitleFormat::CanWriteFile(wxString const& filename) const {
bool SubtitleFormat::CanSave(const AssFile *subs) const { bool SubtitleFormat::CanSave(const AssFile *subs) const {
AssStyle defstyle; 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 // Check style, if anything non-default is found, return false
if (const AssStyle *curstyle = dynamic_cast<const AssStyle*>(&*cur)) { if (const AssStyle *curstyle = dynamic_cast<const AssStyle*>(&line)) {
if (curstyle->GetEntryData() != defstyle.GetEntryData()) if (curstyle->GetEntryData() != defstyle.GetEntryData())
return false; return false;
} }
// Check for attachments, if any is found, return false // Check for attachments, if any is found, return false
if (dynamic_cast<const AssAttachment*>(&*cur)) return false; if (dynamic_cast<const AssAttachment*>(&line)) return false;
// Check dialog // Check dialog
if (const AssDialogue *curdiag = dynamic_cast<const AssDialogue*>(&*cur)) { if (const AssDialogue *curdiag = dynamic_cast<const AssDialogue*>(&line)) {
if (curdiag->GetStrippedText() != curdiag->Text) if (curdiag->GetStrippedText() != curdiag->Text)
return false; return false;
} }
@ -164,16 +164,16 @@ agi::vfr::Framerate SubtitleFormat::AskForFPS(bool allow_vfr, bool show_smpte) {
} }
void SubtitleFormat::StripTags(AssFile &file) { void SubtitleFormat::StripTags(AssFile &file) {
for (entryIter cur = file.Line.begin(); cur != file.Line.end(); ++cur) { for (auto &line : file.Line) {
if (AssDialogue *current = dynamic_cast<AssDialogue*>(&*cur)) { if (AssDialogue *current = dynamic_cast<AssDialogue*>(&line)) {
current->StripTags(); current->StripTags();
} }
} }
} }
void SubtitleFormat::ConvertNewlines(AssFile &file, wxString const& newline, bool mergeLineBreaks) { void SubtitleFormat::ConvertNewlines(AssFile &file, wxString const& newline, bool mergeLineBreaks) {
for (entryIter cur = file.Line.begin(); cur != file.Line.end(); ++cur) { for (auto &line : file.Line) {
if (AssDialogue *current = dynamic_cast<AssDialogue*>(&*cur)) { if (AssDialogue *current = dynamic_cast<AssDialogue*>(&line)) {
current->Text.Replace("\\h", " "); current->Text.Replace("\\h", " ");
current->Text.Replace("\\n", newline); current->Text.Replace("\\n", newline);
current->Text.Replace("\\N", newline); current->Text.Replace("\\N", newline);
@ -321,13 +321,13 @@ void SubtitleFormat::LoadFormats() {
} }
void SubtitleFormat::DestroyFormats() { void SubtitleFormat::DestroyFormats() {
for (std::list<SubtitleFormat*>::iterator it = formats.begin(); it != formats.end(); ) for (auto it = formats.begin(); it != formats.end(); )
delete *it++; delete *it++;
} }
template<class Cont, class Pred> template<class Cont, class Pred>
SubtitleFormat *find_or_throw(Cont &container, Pred pred) { 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()) if (it == container.end())
throw UnknownSubtitleFormatError("Subtitle format for extension not found", 0); throw UnknownSubtitleFormatError("Subtitle format for extension not found", 0);
return *it; return *it;
@ -349,9 +349,7 @@ wxString SubtitleFormat::GetWildcards(int mode) {
wxArrayString all; wxArrayString all;
wxString final; wxString final;
std::list<SubtitleFormat*>::iterator curIter; for (auto format : formats) {
for (curIter=formats.begin();curIter!=formats.end();curIter++) {
SubtitleFormat *format = *curIter;
wxArrayString cur = mode == 0 ? format->GetReadWildcards() : format->GetWriteWildcards(); wxArrayString cur = mode == 0 ? format->GetReadWildcards() : format->GetWriteWildcards();
if (cur.empty()) continue; if (cur.empty()) continue;

View File

@ -92,13 +92,13 @@ void AssSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename,
bool ssa = filename.Right(4).Lower() == ".ssa"; bool ssa = filename.Right(4).Lower() == ".ssa";
wxString group = src->Line.front().group; 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 // Add a blank line between each group
if (cur->group != group) { if (line.group != group) {
file.WriteLineToFile(""); file.WriteLineToFile("");
group = cur->group; group = line.group;
} }
file.WriteLineToFile(ssa ? cur->GetSSAText() : cur->GetEntryData(), true); file.WriteLineToFile(ssa ? line.GetSSAText() : line.GetEntryData(), true);
} }
} }

View File

@ -123,9 +123,8 @@ namespace
{ {
void ProcessOverrides(AssDialogueBlockOverride *ob, bool &underline, bool &italic, int &align, bool style_underline, bool style_italic) void ProcessOverrides(AssDialogueBlockOverride *ob, bool &underline, bool &italic, int &align, bool style_underline, bool style_italic)
{ {
for (std::vector<AssOverrideTag*>::iterator tag = ob->Tags.begin(); tag != ob->Tags.end(); ++tag) for (auto t : ob->Tags)
{ {
AssOverrideTag *t = *tag;
if (t->Name == "\\u") if (t->Name == "\\u")
underline = t->Params[0]->Get<bool>(style_underline); underline = t->Params[0]->Get<bool>(style_underline);
else if (t->Name == "\\i") else if (t->Name == "\\i")
@ -203,15 +202,15 @@ namespace
std::vector<EbuTextRow> new_text; std::vector<EbuTextRow> new_text;
new_text.reserve(text_rows.size()); new_text.reserve(text_rows.size());
for (std::vector<EbuTextRow>::iterator row = text_rows.begin(); row != text_rows.end(); ++row) for (auto const& row : text_rows)
{ {
// Get lengths of each word // Get lengths of each word
std::vector<size_t> word_lengths; std::vector<size_t> 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.push_back(0);
word_lengths.back() += cur_block->text.size(); word_lengths.back() += cur_block.text.size();
} }
std::vector<size_t> split_points = agi::get_wrap_points(word_lengths, (size_t)max_width, (agi::WrapMode)split_type); std::vector<size_t> 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()) if (split_points.empty())
{ {
// Line doesn't need splitting, so copy straight over // Line doesn't need splitting, so copy straight over
new_text.push_back(*row); new_text.push_back(row);
continue; continue;
} }
@ -227,9 +226,9 @@ namespace
new_text.push_back(EbuTextRow()); new_text.push_back(EbuTextRow());
size_t cur_word = 0; size_t cur_word = 0;
size_t split_point = 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) if (split_points[split_point] == cur_word)
{ {
@ -239,7 +238,7 @@ namespace
++cur_word; ++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 bool CheckLineLengths(int max_width) const
{ {
for (std::vector<EbuTextRow>::const_iterator row = text_rows.begin(); row != text_rows.end(); ++row) for (auto const& row : text_rows)
{ {
int line_length = 0; int line_length = 0;
for (EbuTextRow::const_iterator it = row->begin(); it != row->end(); ++it) for (auto const& block : row)
line_length += it->text.size(); line_length += block.text.size();
if (line_length > max_width) if (line_length > max_width)
// early return as soon as any line is over length // early return as soon as any line is over length
@ -281,9 +280,8 @@ namespace
bool underline = style_underline, italic = style_italic; bool underline = style_underline, italic = style_italic;
for (std::vector<AssDialogueBlock*>::iterator bl = line->Blocks.begin(); bl != line->Blocks.end(); ++bl) for (auto b : line->Blocks)
{ {
AssDialogueBlock *b = *bl;
switch (b->GetType()) switch (b->GetType())
{ {
case BLOCK_PLAIN: case BLOCK_PLAIN:
@ -386,9 +384,9 @@ namespace
subs_list.reserve(copy.Line.size()); subs_list.reserve(copy.Line.size());
// convert to intermediate format // convert to intermediate format
for (entryIter orgline = copy.Line.begin(); orgline != copy.Line.end(); ++orgline) for (auto& orgline : copy.Line)
{ {
AssDialogue *line = dynamic_cast<AssDialogue*>(&*orgline); AssDialogue *line = dynamic_cast<AssDialogue*>(&orgline);
if (!line) continue; if (!line) continue;
// add a new subtitle and work on it // add a new subtitle and work on it
@ -455,35 +453,33 @@ namespace
return reinterpret_cast<const char *>(str.wx_str()); return reinterpret_cast<const char *>(str.wx_str());
} }
std::string convert_subtitle_line(std::vector<EbuSubtitle>::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; std::string fullstring;
for (std::vector<EbuTextRow>::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 // formatting is reset at the start of every row, so keep track per row
bool underline = false, italic = false; bool underline = false, italic = false;
for (std::vector<EbuFormattedText>::const_iterator block = row->begin(); block != row->end(); ++block) for (auto const& block : row)
{ {
if (enable_formatting) if (enable_formatting)
{ {
// insert codes for changed formatting // insert codes for changed formatting
if (underline != block->underline) if (underline != block.underline)
fullstring += EBU_FORMAT_UNDERLINE[block->underline]; fullstring += EBU_FORMAT_UNDERLINE[block.underline];
if (italic != block->italic) if (italic != block.italic)
fullstring += EBU_FORMAT_ITALIC[block->italic]; fullstring += EBU_FORMAT_ITALIC[block.italic];
underline = block->underline; underline = block.underline;
italic = block->italic; italic = block.italic;
} }
// convert text to specified encoding // 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; return fullstring;
} }
@ -515,33 +511,33 @@ namespace
std::vector<BlockTTI> tti; std::vector<BlockTTI> tti;
tti.reserve(subs_list.size()); tti.reserve(subs_list.size());
for (std::vector<EbuSubtitle>::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(), std::string fullstring = convert_subtitle_line(sub, encoder.get(),
export_settings.display_standard == EbuExportSettings::DSC_Open); export_settings.display_standard == EbuExportSettings::DSC_Open);
// construct a base block that can be copied and filled // construct a base block that can be copied and filled
BlockTTI base; BlockTTI base;
base.sgn = sub->group_number; base.sgn = sub.group_number;
base.sn = Endian::MachineToLittle(subtitle_number++); base.sn = Endian::MachineToLittle(subtitle_number++);
base.ebn = 255; base.ebn = 255;
base.cf = sub->comment_flag; base.cf = sub.comment_flag;
memset(base.tf, EBU_FORMAT_UNUSED_SPACE, sizeof(base.tf)); 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_in, base.tci);
smpte_at_frame(fps, sub->time_out, base.tco); smpte_at_frame(fps, sub.time_out, base.tco);
base.cs = sub->cumulative_status; base.cs = sub.cumulative_status;
if (export_settings.translate_alignments) if (export_settings.translate_alignments)
{ {
// vertical position // vertical position
if (sub->vertical_position == EbuSubtitle::PositionTop) if (sub.vertical_position == EbuSubtitle::PositionTop)
base.vp = min_row; base.vp = min_row;
else if (sub->vertical_position == EbuSubtitle::PositionMiddle) else if (sub.vertical_position == EbuSubtitle::PositionMiddle)
base.vp = std::min<uint8_t>(min_row, max_row / 2 - (max_row / 5 * sub->text_rows.size())); base.vp = std::min<uint8_t>(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::PositionBottom)
base.vp = max_row - 1; base.vp = max_row - 1;
base.jc = sub->justification_code; base.jc = sub.justification_code;
} }
else else
{ {
@ -687,8 +683,6 @@ void Ebu3264SubtitleFormat::WriteFile(const AssFile *src, wxString const& filena
// write file // write file
agi::io::Save f(STD_STR(filename), true); agi::io::Save f(STD_STR(filename), true);
f.Get().write((const char *)&gsi, sizeof(gsi)); f.Get().write((const char *)&gsi, sizeof(gsi));
for (std::vector<BlockTTI>::iterator block = tti.begin(); block != tti.end(); ++block) for (auto const& block : tti)
{ f.Get().write((const char *)&block, sizeof(block));
f.Get().write((const char *)&*block, sizeof(*block));
}
} }

View File

@ -77,8 +77,8 @@ void EncoreSubtitleFormat::WriteFile(const AssFile *src, wxString const& filenam
// Write lines // Write lines
int i = 0; int i = 0;
TextFileWriter file(filename, "UTF-8"); TextFileWriter file(filename, "UTF-8");
for (constEntryIter cur = copy.Line.begin(); cur != copy.Line.end(); ++cur) { for (auto const& line : copy.Line) {
if (const AssDialogue *current = dynamic_cast<const AssDialogue*>(&*cur)) { if (const AssDialogue *current = dynamic_cast<const AssDialogue*>(&line)) {
++i; ++i;
file.WriteLineToFile(wxString::Format("%i %s %s %s", i, ft.ToSMPTE(current->Start), ft.ToSMPTE(current->End), current->Text)); file.WriteLineToFile(wxString::Format("%i %s %s %s", i, ft.ToSMPTE(current->Start), ft.ToSMPTE(current->End), current->Text));
} }

View File

@ -142,8 +142,8 @@ void MicroDVDSubtitleFormat::WriteFile(const AssFile *src, wxString const& filen
} }
// Write lines // Write lines
for (constEntryIter cur = copy.Line.begin(); cur != copy.Line.end(); ++cur) { for (auto const& line : copy.Line) {
if (const AssDialogue *current = dynamic_cast<const AssDialogue*>(&*cur)) { if (const AssDialogue *current = dynamic_cast<const AssDialogue*>(&line)) {
int start = fps.FrameAtTime(current->Start, agi::vfr::START); int start = fps.FrameAtTime(current->Start, agi::vfr::START);
int end = fps.FrameAtTime(current->End, agi::vfr::END); int end = fps.FrameAtTime(current->End, agi::vfr::END);

View File

@ -509,8 +509,8 @@ void SRTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename,
// Write lines // Write lines
int i=1; int i=1;
for (constEntryIter cur = copy.Line.begin(); cur != copy.Line.end(); ++cur) { for (auto const& line : copy.Line) {
if (const AssDialogue *current = dynamic_cast<const AssDialogue*>(&*cur)) { if (const AssDialogue *current = dynamic_cast<const AssDialogue*>(&line)) {
file.WriteLineToFile(wxString::Format("%d", i++)); file.WriteLineToFile(wxString::Format("%d", i++));
file.WriteLineToFile(WriteSRTTime(current->Start) + " --> " + WriteSRTTime(current->End)); file.WriteLineToFile(WriteSRTTime(current->Start) + " --> " + WriteSRTTime(current->End));
file.WriteLineToFile(ConvertTags(current)); file.WriteLineToFile(ConvertTags(current));
@ -523,26 +523,26 @@ bool SRTSubtitleFormat::CanSave(const AssFile *file) const {
wxString supported_tags[] = { "\\b", "\\i", "\\s", "\\u" }; wxString supported_tags[] = { "\\b", "\\i", "\\s", "\\u" };
AssStyle defstyle; 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 // Check style, if anything non-default is found, return false
if (const AssStyle *curstyle = dynamic_cast<const AssStyle*>(&*cur)) { if (const AssStyle *curstyle = dynamic_cast<const AssStyle*>(&line)) {
if (curstyle->GetEntryData() != defstyle.GetEntryData()) if (curstyle->GetEntryData() != defstyle.GetEntryData())
return false; return false;
} }
// Check for attachments, if any is found, return false // Check for attachments, if any is found, return false
if (dynamic_cast<const AssAttachment*>(&*cur)) return false; if (dynamic_cast<const AssAttachment*>(&line)) return false;
// Check dialogue // Check dialogue
if (const AssDialogue *curdiag = dynamic_cast<const AssDialogue*>(&*cur)) { if (const AssDialogue *curdiag = dynamic_cast<const AssDialogue*>(&line)) {
std::vector<AssDialogueBlock*> blocks = curdiag->ParseTags(); std::vector<AssDialogueBlock*> blocks = curdiag->ParseTags();
for (size_t i = 0; i < blocks.size(); ++i) { for (auto block : blocks) {
AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(blocks[i]); AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block);
if (!ovr) continue; if (!ovr) continue;
// Verify that all overrides used are supported // Verify that all overrides used are supported
for (size_t j = 0; j < ovr->Tags.size(); ++j) { for (auto tag : ovr->Tags) {
if (!std::binary_search(supported_tags, supported_tags + 4, ovr->Tags[j]->Name)) { if (!std::binary_search(supported_tags, std::end(supported_tags), tag->Name)) {
delete_clear(blocks); delete_clear(blocks);
return false; return false;
} }
@ -565,13 +565,12 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const {
std::vector<AssDialogueBlock *> blocks = diag->ParseTags(); std::vector<AssDialogueBlock *> blocks = diag->ParseTags();
for (size_t i = 0; i < blocks.size(); ++i) { for (auto block : blocks) {
if (AssDialogueBlockOverride* block = dynamic_cast<AssDialogueBlockOverride*>(blocks[i])) { if (AssDialogueBlockOverride* ovr = dynamic_cast<AssDialogueBlockOverride*>(block)) {
// Iterate through overrides // Iterate through overrides
for (size_t j = 0; j < block->Tags.size(); j++) { for (auto tag : ovr->Tags) {
AssOverrideTag *tag = block->Tags[j];
if (tag->IsValid() && tag->Name.size() == 2) { if (tag->IsValid() && tag->Name.size() == 2) {
std::map<char, bool>::iterator it = tag_states.find(tag->Name[1]); auto it = tag_states.find(tag->Name[1]);
if (it != tag_states.end()) { if (it != tag_states.end()) {
bool temp = tag->Params[0]->Get(false); bool temp = tag->Params[0]->Get(false);
if (temp && !it->second) if (temp && !it->second)
@ -584,16 +583,16 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const {
} }
} }
// Plain text // Plain text
else if (AssDialogueBlockPlain *plain = dynamic_cast<AssDialogueBlockPlain*>(blocks[i])) { else if (AssDialogueBlockPlain *plain = dynamic_cast<AssDialogueBlockPlain*>(block)) {
final += plain->GetText(); final += plain->GetText();
} }
} }
// Ensure all tags are closed // Ensure all tags are closed
// Otherwise unclosed overrides might affect lines they shouldn't, see bug #809 for example // Otherwise unclosed overrides might affect lines they shouldn't, see bug #809 for example
for (std::map<char, bool>::iterator it = tag_states.begin(); it != tag_states.end(); ++it) { for (auto it : tag_states) {
if (it->second) if (it.second)
final += wxString::Format("</%c>", it->first); final += wxString::Format("</%c>", it.first);
} }
delete_clear(blocks); delete_clear(blocks);

View File

@ -75,8 +75,8 @@ void TranStationSubtitleFormat::WriteFile(const AssFile *src, wxString const& fi
SmpteFormatter ft(fps); SmpteFormatter ft(fps);
TextFileWriter file(filename, encoding); TextFileWriter file(filename, encoding);
AssDialogue *prev = 0; AssDialogue *prev = 0;
for (entryIter it = copy.Line.begin(); it != copy.Line.end(); ++it) { for (auto& line : copy.Line) {
AssDialogue *cur = dynamic_cast<AssDialogue*>(&*it); AssDialogue *cur = dynamic_cast<AssDialogue*>(&line);
if (prev && cur) { if (prev && cur) {
file.WriteLineToFile(ConvertLine(&copy, prev, fps, ft, cur->Start)); file.WriteLineToFile(ConvertLine(&copy, prev, fps, ft, cur->Start));

View File

@ -135,13 +135,13 @@ AssDialogue *TTXTSubtitleFormat::ProcessLine(wxXmlNode *node, AssDialogue *prev,
finalText.reserve(text.size()); finalText.reserve(text.size());
bool in = false; bool in = false;
bool first = true; bool first = true;
for (size_t i = 0; i < text.size(); ++i) { for (auto chr : text) {
if (text[i] == '\'') { if (chr == '\'') {
if (!in && !first) finalText += "\\N"; if (!in && !first) finalText += "\\N";
first = false; first = false;
in = !in; in = !in;
} }
else if (in) finalText += text[i]; else if (in) finalText += chr;
} }
diag->Text = finalText; diag->Text = finalText;
} }
@ -176,8 +176,8 @@ void TTXTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename,
// Create lines // Create lines
const AssDialogue *prev = 0; const AssDialogue *prev = 0;
for (constEntryIter cur = copy.Line.begin(); cur != copy.Line.end(); ++cur) { for (auto const& line : copy.Line) {
const AssDialogue *current = dynamic_cast<const AssDialogue*>(&*cur); const AssDialogue *current = dynamic_cast<const AssDialogue*>(&line);
if (current && !current->Comment) { if (current && !current->Comment) {
WriteLine(root, prev, current); WriteLine(root, prev, current);
prev = current; prev = current;

View File

@ -129,8 +129,8 @@ void TXTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename,
size_t num_actor_names = 0, num_dialogue_lines = 0; size_t num_actor_names = 0, num_dialogue_lines = 0;
// Detect number of lines with Actor field filled out // Detect number of lines with Actor field filled out
for (constEntryIter l = src->Line.begin(); l != src->Line.end(); ++l) { for (auto const& line : src->Line) {
const AssDialogue *dia = dynamic_cast<const AssDialogue*>(&*l); const AssDialogue *dia = dynamic_cast<const AssDialogue*>(&line);
if (dia && !dia->Comment) { if (dia && !dia->Comment) {
num_dialogue_lines++; num_dialogue_lines++;
if (!dia->Actor.empty()) if (!dia->Actor.empty())
@ -146,8 +146,8 @@ void TXTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename,
file.WriteLineToFile(wxString("# Exported by Aegisub ") + GetAegisubShortVersionString()); file.WriteLineToFile(wxString("# Exported by Aegisub ") + GetAegisubShortVersionString());
// Write the file // Write the file
for (constEntryIter l = src->Line.begin(); l != src->Line.end(); ++l) { for (auto const& line : src->Line) {
const AssDialogue *dia = dynamic_cast<const AssDialogue*>(&*l); const AssDialogue *dia = dynamic_cast<const AssDialogue*>(&line);
if (!dia) continue; if (!dia) continue;
wxString out_line; wxString out_line;
@ -161,10 +161,9 @@ void TXTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename,
wxString out_text; wxString out_text;
if (strip_formatting) { if (strip_formatting) {
std::vector<AssDialogueBlock*> blocks = dia->ParseTags(); std::vector<AssDialogueBlock*> blocks = dia->ParseTags();
for (std::vector<AssDialogueBlock*>::iterator block = blocks.begin(); block != blocks.end(); ++block) { for (auto block : blocks) {
if ((*block)->GetType() == BLOCK_PLAIN) { if (block->GetType() == BLOCK_PLAIN)
out_text += (*block)->GetText(); out_text += block->GetText();
}
} }
delete_clear(blocks); delete_clear(blocks);
} }

View File

@ -46,34 +46,28 @@
#include "include/aegisub/subtitles_provider.h" #include "include/aegisub/subtitles_provider.h"
#endif #endif
/// @brief Get provider
/// @return
///
SubtitlesProvider* SubtitlesProviderFactory::GetProvider() { SubtitlesProvider* SubtitlesProviderFactory::GetProvider() {
std::vector<std::string> list = GetClasses(OPT_GET("Subtitle/Provider")->GetString()); std::vector<std::string> list = GetClasses(OPT_GET("Subtitle/Provider")->GetString());
if (list.empty()) throw wxString("No subtitle providers are available."); if (list.empty()) throw wxString("No subtitle providers are available.");
// Get provider // Get provider
wxString error; wxString error;
for (unsigned int i=0;i<list.size();i++) { for (auto const& factory : list) {
try { try {
size_t pos = list[i].find('/'); size_t pos = factory.find('/');
std::string subType = pos < list[i].size() - 1 ? list[i].substr(pos + 1) : ""; std::string subType = pos < factory.size() - 1 ? factory.substr(pos + 1) : "";
SubtitlesProvider *provider = Create(list[i], subType); SubtitlesProvider *provider = Create(factory, subType);
if (provider) return provider; if (provider) return provider;
} }
catch (agi::UserCancelException const&) { throw; } catch (agi::UserCancelException const&) { throw; }
catch (wxString const& err) { error += list[i] + " factory: " + err + "\n"; } catch (wxString const& err) { error += factory + " factory: " + err + "\n"; }
catch (const char *err) { error += list[i] + " factory: " + wxString(err) + "\n"; } catch (const char *err) { error += factory + " factory: " + wxString(err) + "\n"; }
catch (...) { error += list[i] + " factory: Unknown error\n"; } catch (...) { error += factory + " factory: Unknown error\n"; }
} }
// Failed
throw error; throw error;
} }
/// @brief Register providers
///
void SubtitlesProviderFactory::RegisterProviders() { void SubtitlesProviderFactory::RegisterProviders() {
#ifdef WITH_CSRI #ifdef WITH_CSRI
std::vector<std::string> csri_providers(CSRISubtitlesProvider::GetSubTypes()); std::vector<std::string> csri_providers(CSRISubtitlesProvider::GetSubTypes());

View File

@ -75,8 +75,8 @@ std::vector<std::string> Thesaurus::GetLanguageList() const {
dat.Sort(); dat.Sort();
// Drop extensions and the th_ prefix // 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 (auto& fn : idx) fn = fn.Mid(3, fn.size() - 7);
for (size_t i = 0; i < dat.size(); ++i) dat[i] = dat[i].Mid(3, dat[i].size() - 7); for (auto& fn : dat) fn = fn.Mid(3, fn.size() - 7);
// Verify that each idx has a dat // Verify that each idx has a dat
for (size_t i = 0, j = 0; i < idx.size() && j < dat.size(); ) { for (size_t i = 0, j = 0; i < idx.size() && j < dat.size(); ) {

View File

@ -104,8 +104,8 @@ std::shared_ptr<AegiVideoFrame> ThreadedFrameSource::ProcFrame(int frameNum, dou
// instead muck around with its innards to just temporarily // instead muck around with its innards to just temporarily
// remove the non-visible lines without deleting them // remove the non-visible lines without deleting them
std::deque<AssEntry*> full; std::deque<AssEntry*> full;
for (entryIter it = subs->Line.begin(); it != subs->Line.end(); ++it) for (auto& line : subs->Line)
full.push_back(&*it); full.push_back(&line);
subs->Line.remove_if(invisible_line(time)); subs->Line.remove_if(invisible_line(time));
try { try {

View File

@ -114,9 +114,7 @@ namespace {
bool needs_onidle = false; bool needs_onidle = false;
bool last_was_sep = false; bool last_was_sep = false;
for (json::Array::const_iterator it = arr.begin(); it != arr.end(); ++it) { for (json::String const& command_name : arr) {
json::String const& command_name = *it;
if (command_name.empty()) { if (command_name.empty()) {
if (!last_was_sep) if (!last_was_sep)
AddSeparator(); AddSeparator();

View File

@ -402,19 +402,19 @@ class cache_cleaner : public wxThread {
} }
int deleted = 0; int deleted = 0;
for (std::multimap<int64_t,wxFileName>::iterator i = cachefiles.begin(); i != cachefiles.end(); i++) { for (auto const& i : cachefiles) {
// stop cleaning? // stop cleaning?
if ((total_size <= max_size && cachefiles.size() - deleted <= max_files) || cachefiles.size() - deleted < 2) if ((total_size <= max_size && cachefiles.size() - deleted <= max_files) || cachefiles.size() - deleted < 2)
break; break;
int64_t fsize = i->second.GetSize().GetValue(); int64_t fsize = i.second.GetSize().GetValue();
#ifdef __WXMSW__ #ifdef __WXMSW__
int res = wxRemove(i->second.GetFullPath()); int res = wxRemove(i.second.GetFullPath());
#else #else
int res = unlink(i->second.GetFullPath().fn_str()); int res = unlink(i.second.GetFullPath().fn_str());
#endif #endif
if (res) { 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; continue;
} }

View File

@ -289,9 +289,7 @@ void VideoOutGL::UploadFrameData(const AegiVideoFrame& frame) {
// Set the row length, needed to be able to upload partial rows // Set the row length, needed to be able to upload partial rows
CHECK_ERROR(glPixelStorei(GL_UNPACK_ROW_LENGTH, frame.pitch / frame.GetBpp())); CHECK_ERROR(glPixelStorei(GL_UNPACK_ROW_LENGTH, frame.pitch / frame.GetBpp()));
for (unsigned i = 0; i < textureList.size(); i++) { for (auto& ti : textureList) {
TextureInfo& ti = textureList[i];
CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, ti.textureID)); CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, ti.textureID));
CHECK_ERROR(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ti.sourceW, CHECK_ERROR(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ti.sourceW,
ti.sourceH, format, GL_UNSIGNED_BYTE, frame.data + ti.dataOffset)); ti.sourceH, format, GL_UNSIGNED_BYTE, frame.data + ti.dataOffset));

View File

@ -63,7 +63,7 @@ const AegiVideoFrame VideoProviderCache::GetFrame(int n) {
size_t total_size = 0; size_t total_size = 0;
// See if frame is cached // See if frame is cached
for (boost::container::list<CachedFrame>::iterator cur = cache.begin(); cur != cache.end(); ++cur) { for (auto cur = cache.begin(); cur != cache.end(); ++cur) {
if (cur->frame_number == n) { if (cur->frame_number == n) {
cache.push_front(*cur); cache.push_front(*cur);
cache.erase(cur); cache.erase(cur);

View File

@ -64,32 +64,32 @@ VideoProvider *VideoProviderFactory::GetProvider(wxString video) {
bool fileSupported = false; bool fileSupported = false;
std::string errors; std::string errors;
errors.reserve(1024); errors.reserve(1024);
for (int i = 0; i < (signed)list.size(); ++i) { for (auto const& factory : list) {
std::string err; std::string err;
try { try {
VideoProvider *provider = Create(list[i], video); VideoProvider *provider = Create(factory, video);
LOG_I("manager/video/provider") << list[i] << ": opened " << STD_STR(video); LOG_I("manager/video/provider") << factory << ": opened " << STD_STR(video);
if (provider->WantsCaching()) { if (provider->WantsCaching()) {
return new VideoProviderCache(provider); return new VideoProviderCache(provider);
} }
return provider; return provider;
} }
catch (agi::FileNotFoundError const&) { 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 // Keep trying other providers as this one may just not be able to
// open a valid path // open a valid path
} }
catch (VideoNotSupported const&) { catch (VideoNotSupported const&) {
fileFound = true; 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) { catch (VideoOpenError const& ex) {
fileSupported = true; fileSupported = true;
err = list[i] + ": " + ex.GetMessage(); err = factory + ": " + ex.GetMessage();
} }
catch (agi::vfr::Error const& ex) { catch (agi::vfr::Error const& ex) {
fileSupported = true; fileSupported = true;
err = list[i] + ": " + ex.GetMessage(); err = factory + ": " + ex.GetMessage();
} }
errors += err; errors += err;
errors += "\n"; errors += "\n";

View File

@ -204,8 +204,8 @@ void VideoSlider::OnPaint(wxPaintEvent &) {
int curX; int curX;
if (OPT_GET("Video/Slider/Show Keyframes")->GetBool()) { if (OPT_GET("Video/Slider/Show Keyframes")->GetBool()) {
dc.SetPen(wxPen(shad)); dc.SetPen(wxPen(shad));
for (size_t i=0;i<keyframes.size();i++) { for (int frame : keyframes) {
curX = GetXAtValue(keyframes[i]); curX = GetXAtValue(frame);
dc.DrawLine(curX,2,curX,8); dc.DrawLine(curX,2,curX,8);
} }
} }

View File

@ -337,8 +337,8 @@ template<class FeatureType>
void VisualTool<FeatureType>::RemoveSelection(feature_iterator feat) { void VisualTool<FeatureType>::RemoveSelection(feature_iterator feat) {
if (!sel_features.erase(feat) || !feat->line) return; if (!sel_features.erase(feat) || !feat->line) return;
for (selection_iterator it = sel_features.begin(); it != sel_features.end(); ++it) { for (auto sel : sel_features) {
if ((*it)->line == feat->line) return; if (sel->line == feat->line) return;
} }
SubtitleSelection sel = c->selectionController->GetSelectedSet(); 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 // 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) { static param_vec find_tag(const AssDialogue *line, wxString tag_name) {
for (size_t i = 0; i < line->Blocks.size(); ++i) { for (auto block : line->Blocks) {
const AssDialogueBlockOverride *ovr = dynamic_cast<const AssDialogueBlockOverride*>(line->Blocks[i]); const AssDialogueBlockOverride *ovr = dynamic_cast<const AssDialogueBlockOverride*>(block);
if (!ovr) continue; if (!ovr) continue;
for (size_t j = 0; j < ovr->Tags.size(); ++j) { for (auto tag : ovr->Tags) {
if (ovr->Tags[j]->Name == tag_name) if (tag->Name == tag_name)
return &ovr->Tags[j]->Params; return &tag->Params;
} }
} }

View File

@ -116,12 +116,11 @@ void VisualToolClip::UpdateHold() {
void VisualToolClip::CommitHold() { void VisualToolClip::CommitHold() {
wxString value = wxString::Format("(%s,%s)", ToScriptCoords(cur_1.Min(cur_2)).Str(), ToScriptCoords(cur_1.Max(cur_2)).Str()); 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 (auto line : c->selectionController->GetSelectedSet()) {
for (SubtitleSelection::iterator it = sel.begin(); it != sel.end(); ++it) {
// This check is technically not correct as it could be outside of an // This check is technically not correct as it could be outside of an
// override block... but that's rather unlikely // override block... but that's rather unlikely
bool has_iclip = (*it)->Text.find("\\iclip") != wxString::npos; bool has_iclip = line->Text.find("\\iclip") != wxString::npos;
SetOverride(*it, has_iclip ? "\\iclip" : "\\clip", value); SetOverride(line, has_iclip ? "\\iclip" : "\\clip", value);
} }
} }

View File

@ -40,21 +40,20 @@ VisualToolCross::~VisualToolCross() {
void VisualToolCross::OnDoubleClick() { void VisualToolCross::OnDoubleClick() {
Vector2D d = ToScriptCoords(mouse_pos) - GetLinePosition(active_line); Vector2D d = ToScriptCoords(mouse_pos) - GetLinePosition(active_line);
SubtitleSelection sel = c->selectionController->GetSelectedSet(); for (auto line : c->selectionController->GetSelectedSet()) {
for (SubtitleSelection::const_iterator it = sel.begin(); it != sel.end(); ++it) {
Vector2D p1, p2; Vector2D p1, p2;
int t1, t2; int t1, t2;
if (GetLineMove(*it, p1, p2, t1, t2)) { if (GetLineMove(line, p1, p2, t1, t2)) {
if (t1 > 0 || t2 > 0) 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 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 else
SetOverride(*it, "\\pos", "(" + Text(GetLinePosition(*it) + d) + ")"); SetOverride(line, "\\pos", "(" + Text(GetLinePosition(line) + d) + ")");
if (Vector2D org = GetLineOrigin(*it)) if (Vector2D org = GetLineOrigin(line))
SetOverride(*it, "\\org", "(" + Text(org + d) + ")"); SetOverride(line, "\\org", "(" + Text(org + d) + ")");
} }
Commit(_("positioning")); Commit(_("positioning"));

View File

@ -81,8 +81,7 @@ void VisualToolDrag::UpdateToggleButtons() {
void VisualToolDrag::OnSubTool(wxCommandEvent &) { void VisualToolDrag::OnSubTool(wxCommandEvent &) {
// Toggle \move <-> \pos // Toggle \move <-> \pos
VideoContext *vc = c->videoController; VideoContext *vc = c->videoController;
for (SubtitleSelection::const_iterator cur = selection.begin(); cur != selection.end(); ++cur) { for (auto line : selection) {
AssDialogue *line = *cur;
Vector2D p1, p2; Vector2D p1, p2;
int t1, t2; int t1, t2;
@ -115,8 +114,8 @@ void VisualToolDrag::OnFileChanged() {
primary = 0; primary = 0;
active_feature = features.end(); active_feature = features.end();
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { for (auto& line : c->ass->Line) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it); AssDialogue *diag = dynamic_cast<AssDialogue*>(&line);
if (diag && IsDisplayed(diag)) if (diag && IsDisplayed(diag))
MakeFeatures(diag); MakeFeatures(diag);
} }
@ -131,8 +130,8 @@ void VisualToolDrag::OnFrameChanged() {
feature_iterator feat = features.begin(); feature_iterator feat = features.begin();
feature_iterator end = features.end(); feature_iterator end = features.end();
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { for (auto& line : c->ass->Line) {
AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it); AssDialogue *diag = dynamic_cast<AssDialogue*>(&line);
if (!diag) continue; if (!diag) continue;
if (IsDisplayed(diag)) { if (IsDisplayed(diag)) {
@ -282,9 +281,8 @@ bool VisualToolDrag::InitializeDrag(feature_iterator feature) {
int time = c->videoController->TimeAtFrame(frame_number) - feature->line->Start; int time = c->videoController->TimeAtFrame(frame_number) - feature->line->Start;
int change = time - feature->time; int change = time - feature->time;
for (sel_iterator cur = sel_features.begin(); cur != sel_features.end(); ++cur) { for (auto feat : sel_features)
(*cur)->time += change; feat->time += change;
}
} }
return true; return true;
} }
@ -312,21 +310,20 @@ void VisualToolDrag::UpdateDrag(feature_iterator feature) {
void VisualToolDrag::OnDoubleClick() { void VisualToolDrag::OnDoubleClick() {
Vector2D d = ToScriptCoords(mouse_pos) - (primary ? ToScriptCoords(primary->pos) : GetLinePosition(active_line)); Vector2D d = ToScriptCoords(mouse_pos) - (primary ? ToScriptCoords(primary->pos) : GetLinePosition(active_line));
SubtitleSelection sel = c->selectionController->GetSelectedSet(); for (auto line : c->selectionController->GetSelectedSet()) {
for (SubtitleSelection::const_iterator it = sel.begin(); it != sel.end(); ++it) {
Vector2D p1, p2; Vector2D p1, p2;
int t1, t2; int t1, t2;
if (GetLineMove(*it, p1, p2, t1, t2)) { if (GetLineMove(line, p1, p2, t1, t2)) {
if (t1 > 0 || t2 > 0) 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 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 else
SetOverride(*it, "\\pos", (GetLinePosition(*it) + d).PStr()); SetOverride(line, "\\pos", (GetLinePosition(line) + d).PStr());
if (Vector2D org = GetLineOrigin(*it)) if (Vector2D org = GetLineOrigin(line))
SetOverride(*it, "\\org", (org + d).PStr()); SetOverride(line, "\\org", (org + d).PStr());
} }
Commit(_("positioning")); Commit(_("positioning"));

View File

@ -133,10 +133,10 @@ void VisualToolVectorClip::Draw() {
// Draw lines connecting the bicubic features // Draw lines connecting the bicubic features
gl.SetLineColour(colour[3], 0.9f, 1); gl.SetLineColour(colour[3], 0.9f, 1);
for (Spline::iterator cur = spline.begin(); cur != spline.end(); ++cur) { for (auto const& curve : spline) {
if (cur->type == SplineCurve::BICUBIC) { if (curve.type == SplineCurve::BICUBIC) {
gl.DrawDashedLine(cur->p1, cur->p2, 6); gl.DrawDashedLine(curve.p1, curve.p2, 6);
gl.DrawDashedLine(cur->p3, cur->p4, 6); gl.DrawDashedLine(curve.p3, curve.p4, 6);
} }
} }
@ -204,12 +204,11 @@ void VisualToolVectorClip::Save() {
value += wxString::Format("%d,", spline.GetScale()); value += wxString::Format("%d,", spline.GetScale());
value += spline.EncodeToAss() + ")"; value += spline.EncodeToAss() + ")";
SubtitleSelection sel = c->selectionController->GetSelectedSet(); for (auto line : c->selectionController->GetSelectedSet()) {
for (SubtitleSelection::iterator it = sel.begin(); it != sel.end(); ++it) {
// This check is technically not correct as it could be outside of an // This check is technically not correct as it could be outside of an
// override block... but that's rather unlikely // override block... but that's rather unlikely
bool has_iclip = (*it)->Text.find("\\iclip") != wxString::npos; bool has_iclip = line->Text.find("\\iclip") != wxString::npos;
SetOverride(*it, has_iclip ? "\\iclip" : "\\clip", value); SetOverride(line, has_iclip ? "\\iclip" : "\\clip", value);
} }
} }