diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/exceptions.cc | 5 | ||||
| -rw-r--r-- | src/exceptions.h | 7 | ||||
| -rw-r--r-- | src/subrip_reader.cc | 16 | ||||
| -rw-r--r-- | src/subrip_reader.h | 2 |
4 files changed, 19 insertions, 11 deletions
diff --git a/src/exceptions.cc b/src/exceptions.cc index d09be61..df9ae9a 100644 --- a/src/exceptions.cc +++ b/src/exceptions.cc @@ -31,8 +31,9 @@ ProgrammingError::ProgrammingError (string file, int line) } -SubripError::SubripError (string saw, string expecting, list<string> context) - : runtime_error ("Error in SubRip file: saw " + (saw.empty() ? "an empty string" : saw) + " when expecting " + expecting) +SubripError::SubripError(int line_number, string saw, string expecting, list<string> context) + : runtime_error(String::compose("Error in SubRip file line %1: saw %2 when expecting %3", line_number, saw.empty() ? "an empty string" : saw, expecting).c_str()) + , _line_number(line_number) , _context (context) { diff --git a/src/exceptions.h b/src/exceptions.h index 3b2961d..58659ad 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -55,13 +55,18 @@ public: class SubripError : public std::runtime_error { public: - SubripError (std::string saw, std::string expecting, std::list<std::string> context); + SubripError(int line_number, std::string saw, std::string expecting, std::list<std::string> context); std::list<std::string> context () const { return _context; } + int line_number() const { + return _line_number; + } + private: + int _line_number; std::list<std::string> _context; }; diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index 0e948f9..b95e6be 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -79,9 +79,11 @@ SubripReader::read (function<optional<string> ()> get_line) RawSubtitle rs; prepare(rs); + int line_number = 0; while (true) { auto line = get_line (); + ++line_number; if (!line) { break; } @@ -123,19 +125,19 @@ SubripReader::read (function<optional<string> ()> get_line) _context.push_back (*ex); } } - throw SubripError (*line, "a time/position line", _context); + throw SubripError(line_number, *line, "a time/position line", _context); } string expected; auto from = convert_time(p[0], ",", &expected); if (!from) { - throw SubripError(p[0], expected, _context); + throw SubripError(line_number, p[0], expected, _context); } rs.from = *from; auto to = convert_time(p[2], ",", &expected); if (!to) { - throw SubripError(p[2], expected, _context); + throw SubripError(line_number, p[2], expected, _context); } rs.to = *to; @@ -154,7 +156,7 @@ SubripReader::read (function<optional<string> ()> get_line) */ boost::algorithm::split_regex(sub_lines, *line, boost::regex("\xe2\x80\xa8")); for (auto sub_line: sub_lines) { - convert_line(sub_line, rs); + convert_line(line_number, sub_line, rs); rs.vertical_position.line = rs.vertical_position.line.get() + 1; rs.text.clear(); } @@ -221,7 +223,7 @@ SubripReader::convert_time(string t, string milliseconds_separator, string* expe } void -SubripReader::convert_line (string t, RawSubtitle& p) +SubripReader::convert_line(int line_number, string t, RawSubtitle& p) { vector<Colour> colours; colours.push_back (Colour (1, 1, 1)); @@ -276,7 +278,7 @@ SubripReader::convert_line (string t, RawSubtitle& p) p.colour = Colour::from_rgba_hex(match[1]); colours.push_back(p.colour); } else { - throw SubripError(tag, "a colour in the format #rrggbb #rrggbbaa or rgba(rr,gg,bb,aa)", _context); + throw SubripError(line_number, tag, "a colour in the format #rrggbb #rrggbbaa or rgba(rr,gg,bb,aa)", _context); } } else { re = boost::regex ( @@ -293,7 +295,7 @@ SubripReader::convert_line (string t, RawSubtitle& p) p.colour.b = raw_convert<int>(string(match[3])) / 255.0; colours.push_back (p.colour); } else { - throw SubripError (tag, "a colour in the format #rrggbb #rrggbbaa or rgba(rr,gg,bb,aa)", _context); + throw SubripError(line_number, tag, "a colour in the format #rrggbb #rrggbbaa or rgba(rr,gg,bb,aa)", _context); } } } else if (has_next(t, i, "</font>")) { diff --git a/src/subrip_reader.h b/src/subrip_reader.h index 83fefdf..bf438ed 100644 --- a/src/subrip_reader.h +++ b/src/subrip_reader.h @@ -51,7 +51,7 @@ private: friend struct ::subrip_reader_test6; SubripReader () {} - void convert_line (std::string t, RawSubtitle& p); + void convert_line(int line_number, std::string t, RawSubtitle& p); void maybe_content (RawSubtitle& p); void read (boost::function<boost::optional<std::string> ()> get_line); |
