diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-11-14 00:38:49 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-11-14 00:38:51 +0100 |
| commit | e30e83c698a866f2bea2118804683097be589cc9 (patch) | |
| tree | 2311db383e2b6021431a795868ee12c7775ed952 | |
| parent | db4a3dbc4aa4cdcffb96c67b8f6d4d68c5467933 (diff) | |
Allow SubripReader::convert_time to take a milliseconds separator.
Maybe this method should just be on its own somewhere now.
| -rw-r--r-- | src/subrip_reader.cc | 23 | ||||
| -rw-r--r-- | src/subrip_reader.h | 2 | ||||
| -rw-r--r-- | test/subrip_reader_test.cc | 4 |
3 files changed, 16 insertions, 13 deletions
diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index 926511a..a59b43f 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -21,20 +21,23 @@ * @brief SubripReader class. */ -#include "subrip_reader.h" + +#include "compose.hpp" #include "exceptions.h" -#include "util.h" -#include "sub_assert.h" #include "raw_convert.h" #include "ssa_reader.h" +#include "sub_assert.h" +#include "subrip_reader.h" +#include "util.h" #include <boost/algorithm/string.hpp> #include <boost/algorithm/string_regex.hpp> +#include <boost/bind.hpp> #include <boost/lexical_cast.hpp> #include <boost/regex.hpp> -#include <boost/bind.hpp> #include <cstdio> -#include <vector> #include <iostream> +#include <vector> + using std::string; using std::vector; @@ -125,13 +128,13 @@ SubripReader::read (function<optional<string> ()> get_line) } string expected; - auto from = convert_time(p[0], &expected); + auto from = convert_time(p[0], ",", &expected); if (!from) { throw SubripError(p[0], expected, _context); } rs.from = *from; - auto to = convert_time(p[2], &expected); + auto to = convert_time(p[2], ",", &expected); if (!to) { throw SubripError(p[2], expected, _context); } @@ -163,7 +166,7 @@ SubripReader::read (function<optional<string> ()> get_line) } optional<Time> -SubripReader::convert_time(string t, string* expected) +SubripReader::convert_time(string t, string milliseconds_separator, string* expected) { auto report_expected = [expected](string const& s) { if (expected) { @@ -179,9 +182,9 @@ SubripReader::convert_time(string t, string* expected) } vector<string> b; - boost::algorithm::split (b, a[2], boost::is_any_of (",")); + boost::algorithm::split(b, a[2], boost::is_any_of(milliseconds_separator)); if (b.size() != 2) { - report_expected("time in the format h:m:s,ms"); + report_expected(String::compose("time in the format h:m:s%1ms", milliseconds_separator)); return {}; } diff --git a/src/subrip_reader.h b/src/subrip_reader.h index e29002f..83fefdf 100644 --- a/src/subrip_reader.h +++ b/src/subrip_reader.h @@ -41,7 +41,7 @@ public: SubripReader (FILE* f); SubripReader (std::string subs); - static boost::optional<Time> convert_time(std::string t, std::string* expected = nullptr); + static boost::optional<Time> convert_time(std::string t, std::string milliseconds_separator, std::string* expected = nullptr); private: /* For tests */ diff --git a/test/subrip_reader_test.cc b/test/subrip_reader_test.cc index 6029b23..aa37602 100644 --- a/test/subrip_reader_test.cc +++ b/test/subrip_reader_test.cc @@ -408,10 +408,10 @@ BOOST_AUTO_TEST_CASE (subrip_reader_convert_line_test) BOOST_AUTO_TEST_CASE (subrip_reader_convert_time_test) { sub::SubripReader reader; - auto t = reader.convert_time("00:03:10,500"); + auto t = reader.convert_time("00:03:10,500", ","); BOOST_REQUIRE(t); BOOST_CHECK_EQUAL(*t, sub::Time::from_hms(0, 3, 10, 500)); - t = reader.convert_time("04:19:51,782"); + t = reader.convert_time("04:19:51,782", ","); BOOST_REQUIRE(t); BOOST_CHECK_EQUAL(*t, sub::Time::from_hms(4, 19, 51, 782)); } |
