X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fsubrip_reader.cc;h=45da3ab949d4324767b3068ca65d19a1c512b1a9;hb=2163c97965b8e31ac1af28cfa8c80cf2ed85f31e;hp=94a48c09bf4d06741c6cbf931f585537babb8ba4;hpb=e245921978ee9c7c6e025c7416bdf808d789fa44;p=libsub.git diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index 94a48c0..45da3ab 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -83,6 +83,12 @@ SubripReader::read (function ()> get_line) trim_right_if (*line, boost::is_any_of ("\n\r")); remove_unicode_bom (line); + /* Keep some history in case there is an error to report */ + _context.push_back (*line); + if (_context.size() > 5) { + _context.pop_front (); + } + switch (state) { case COUNTER: { @@ -107,9 +113,15 @@ SubripReader::read (function ()> get_line) /* Further trim this line, removing spaces from the end */ trim_right_if (*line, boost::is_any_of (" ")); - boost::algorithm::split (p, *line, boost::algorithm::is_any_of (" ")); + boost::algorithm::split (p, *line, boost::algorithm::is_any_of (" "), boost::token_compress_on); if (p.size() != 3 && p.size() != 7) { - throw SubripError (*line, "a time/position line"); + for (int i = 0; i < 2; ++i) { + optional ex = get_line (); + if (ex) { + _context.push_back (*ex); + } + } + throw SubripError (*line, "a time/position line", _context); } rs.from = convert_time (p[0]); @@ -138,7 +150,7 @@ SubripReader::convert_time (string t) vector a; boost::algorithm::split (a, t, boost::is_any_of (":")); if (a.size() != 3) { - throw SubripError (t, "time in the format h:m:s,ms"); + throw SubripError (t, "time in the format h:m:s,ms", _context); } vector b;