From cafee6f81257fa81ee302b5d3ffa82213a0a6a44 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 13 Jan 2021 13:04:04 +0100 Subject: Replace list with vector in most of the API. --- src/util.cc | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'src/util.cc') diff --git a/src/util.cc b/src/util.cc index c347375..eb68752 100644 --- a/src/util.cc +++ b/src/util.cc @@ -32,8 +32,9 @@ using std::getline; using std::ostream; using std::map; using std::list; -using boost::optional; using std::shared_ptr; +using std::vector; +using boost::optional; using namespace sub; /** @param s A string. @@ -100,27 +101,27 @@ sub::remove_unicode_bom (optional& line) void sub::dump (shared_ptr reader, ostream& os) { - map metadata = reader->metadata (); - for (map::const_iterator i = metadata.begin(); i != metadata.end(); ++i) { - os << i->first << ": " << i->second << "\n"; + auto metadata = reader->metadata (); + for (auto const& i: metadata) { + os << i.first << ": " << i.second << "\n"; } - list subs = collect > (reader->subtitles ()); + auto subs = collect> (reader->subtitles()); int n = 0; - for (list::const_iterator i = subs.begin(); i != subs.end(); ++i) { - os << "Subtitle " << n << " at " << i->from << " -> " << i->to << "\n"; - for (list::const_iterator j = i->lines.begin(); j != i->lines.end(); ++j) { + for (auto const& i: subs) { + os << "Subtitle " << n << " at " << i.from << " -> " << i.to << "\n"; + for (auto const& j: i.lines) { os << "\t"; - if (j->vertical_position.proportional) { - os << j->vertical_position.proportional.get() << " of screen"; - } else if (j->vertical_position.line && j->vertical_position.lines) { - os << j->vertical_position.line.get() << " lines of " << j->vertical_position.lines.get(); + if (j.vertical_position.proportional) { + os << j.vertical_position.proportional.get() << " of screen"; + } else if (j.vertical_position.line && j.vertical_position.lines) { + os << j.vertical_position.line.get() << " lines of " << j.vertical_position.lines.get(); } - if (j->vertical_position.reference) { + if (j.vertical_position.reference) { os << " from "; - switch (j->vertical_position.reference.get()) { + switch (j.vertical_position.reference.get()) { case TOP_OF_SCREEN: os << "top"; break; @@ -139,22 +140,22 @@ sub::dump (shared_ptr reader, ostream& os) os << "\t"; bool italic = false; bool underline = false; - for (list::const_iterator k = j->blocks.begin(); k != j->blocks.end(); ++k) { - if (k->italic && !italic) { + for (auto const& k: j.blocks) { + if (k.italic && !italic) { os << ""; - } else if (italic && !k->italic) { + } else if (italic && !k.italic) { os << ""; } - if (k->underline && !underline) { + if (k.underline && !underline) { os << ""; - } else if (underline && !k->underline) { + } else if (underline && !k.underline) { os << ""; } - italic = k->italic; - underline = k->underline; + italic = k.italic; + underline = k.underline; - os << k->text; + os << k.text; } if (italic) { -- cgit v1.2.3