diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-01-15 11:07:04 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-01-15 11:07:04 +0000 |
| commit | a890bedf688f0066d70dd5e9b07cbd86736cc0b1 (patch) | |
| tree | 683fdd79cfd5e218df23a46fa990b1965f6e5b59 /src/lib | |
| parent | f9608c5299d0a58bc01b33e521d89a80be26ed23 (diff) | |
More testing / SubRip parse fixes.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/subrip.cc | 14 | ||||
| -rw-r--r-- | src/lib/subrip.h | 2 | ||||
| -rw-r--r-- | src/lib/subrip_content.cc | 4 | ||||
| -rw-r--r-- | src/lib/subrip_content.h | 4 |
4 files changed, 20 insertions, 4 deletions
diff --git a/src/lib/subrip.cc b/src/lib/subrip.cc index 1fdadf87e..04765532f 100644 --- a/src/lib/subrip.cc +++ b/src/lib/subrip.cc @@ -29,6 +29,7 @@ using std::string; using std::list; using std::vector; +using std::cout; using boost::shared_ptr; using boost::lexical_cast; using boost::algorithm::trim; @@ -54,8 +55,12 @@ SubRip::SubRip (shared_ptr<SubRipContent> content) while (!feof (f)) { fgets (buffer, sizeof (buffer), f); + if (feof (f)) { + break; + } + string line (buffer); - trim (line); + trim_right_if (line, boost::is_any_of ("\n\r")); switch (state) { case COUNTER: @@ -93,6 +98,7 @@ SubRip::SubRip (shared_ptr<SubRipContent> content) current->y1 = convert_coordinate (p[5]); current->y2 = convert_coordinate (p[6]); } + state = CONTENT; break; } case CONTENT: @@ -109,6 +115,11 @@ SubRip::SubRip (shared_ptr<SubRipContent> content) } } + if (state == CONTENT) { + current->pieces = convert_content (lines); + _subtitles.push_back (current.get ()); + } + fclose (f); } @@ -217,7 +228,6 @@ SubRip::convert_content (list<string> t) Time SubRip::length () const { - boost::mutex::scoped_lock lm (_mutex); if (_subtitles.empty ()) { return 0; } diff --git a/src/lib/subrip.h b/src/lib/subrip.h index 0f4fe5d29..6451c105f 100644 --- a/src/lib/subrip.h +++ b/src/lib/subrip.h @@ -23,6 +23,7 @@ class SubRipContent; class subrip_time_test; class subrip_coordinate_test; class subrip_content_test; +class subrip_parse_test; class SubRip { @@ -35,6 +36,7 @@ private: friend class subrip_time_test; friend class subrip_coordinate_test; friend class subrip_content_test; + friend class subrip_parse_test; static Time convert_time (std::string); static int convert_coordinate (std::string); diff --git a/src/lib/subrip_content.cc b/src/lib/subrip_content.cc index 74bba33ba..b13f64ded 100644 --- a/src/lib/subrip_content.cc +++ b/src/lib/subrip_content.cc @@ -19,6 +19,7 @@ #include "subrip_content.h" #include "util.h" +#include "subrip.h" #include "i18n.h" @@ -33,7 +34,7 @@ SubRipContent::SubRipContent (shared_ptr<const Film> film, boost::filesystem::pa } -SubRipContent::SubRipContent (shared_ptr<const Film> film, shared_ptr<const cxml::Node> node, int version) +SubRipContent::SubRipContent (shared_ptr<const Film> film, shared_ptr<const cxml::Node> node, int) : Content (film, node) , SubtitleContent (film, node) { @@ -96,4 +97,3 @@ SubRipContent::identifier () const return s.str (); } - diff --git a/src/lib/subrip_content.h b/src/lib/subrip_content.h index 741e1a4c3..30a824eec 100644 --- a/src/lib/subrip_content.h +++ b/src/lib/subrip_content.h @@ -25,6 +25,10 @@ public: SubRipContent (boost::shared_ptr<const Film>, boost::filesystem::path); SubRipContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>, int); + boost::shared_ptr<SubRipContent> shared_from_this () { + return boost::dynamic_pointer_cast<SubRipContent> (Content::shared_from_this ()); + } + void examine (boost::shared_ptr<Job>); std::string summary () const; std::string technical_summary () const; |
