X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Futil.cc;h=e53e71455b0e3d60ec47ca9b6686bdcf206855ee;hb=17269578ff0164ffacf062d9a6e923eaf5f79ab3;hp=66490c1aeaeb001a83a4ac723cd94211307cf9b3;hpb=d848eed414a5d5c8bc35a3ec843f01e8b609f60d;p=libsub.git diff --git a/src/util.cc b/src/util.cc index 66490c1..e53e714 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2020 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,15 +18,24 @@ */ #include "util.h" +#include +#include "reader.h" +#include "subtitle.h" +#include "collect.h" +#include #include -#include #include #include +#include using std::string; -using std::stringstream; using std::getline; +using std::ostream; +using std::map; +using std::list; using boost::optional; +using boost::shared_ptr; +using namespace sub; /** @param s A string. * @return true if the string contains only space, newline or tab characters, or is empty. @@ -44,7 +53,7 @@ sub::empty_or_white_space (string s) } optional -sub::get_line_stringstream (stringstream* str) +sub::get_line_stringstream (locked_stringstream* str) { if (!str->good ()) { return optional (); @@ -81,3 +90,76 @@ sub::remove_unicode_bom (optional& line) line = line->substr (3); } } + +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"; + } + + list 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) { + + 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.reference) { + os << " from "; + switch (j->vertical_position.reference.get()) { + case TOP_OF_SCREEN: + os << "top"; + break; + case VERTICAL_CENTRE_OF_SCREEN: + os << "centre"; + break; + case BOTTOM_OF_SCREEN: + os << "bottom"; + break; + case TOP_OF_SUBTITLE: + os << "top of subtitle"; + break; + } + } + + 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) { + os << ""; + } else if (italic && !k->italic) { + os << ""; + } + if (k->underline && !underline) { + os << ""; + } else if (underline && !k->underline) { + os << ""; + } + + italic = k->italic; + underline = k->underline; + + os << k->text; + } + + if (italic) { + os << ""; + } + if (underline) { + os << ""; + } + os << "\n"; + } + + ++n; + } +}