summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/exceptions.cc11
-rw-r--r--src/exceptions.h14
-rw-r--r--src/subrip_reader.cc16
-rw-r--r--src/subrip_reader.h4
-rw-r--r--src/wscript1
5 files changed, 38 insertions, 8 deletions
diff --git a/src/exceptions.cc b/src/exceptions.cc
index 4d9d29f..d59d32a 100644
--- a/src/exceptions.cc
+++ b/src/exceptions.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
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
@@ -19,8 +19,10 @@
#include "compose.hpp"
#include "exceptions.h"
+#include <boost/foreach.hpp>
using std::string;
+using std::list;
using namespace sub;
ProgrammingError::ProgrammingError (string file, int line)
@@ -28,3 +30,10 @@ 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)
+ , _context (context)
+{
+
+}
diff --git a/src/exceptions.h b/src/exceptions.h
index c6f7f1a..c7a3c71 100644
--- a/src/exceptions.h
+++ b/src/exceptions.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
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
@@ -22,6 +22,7 @@
#include <stdexcept>
#include <string>
+#include <list>
namespace sub {
@@ -53,9 +54,14 @@ public:
class SubripError : public std::runtime_error
{
public:
- SubripError (std::string saw, std::string expecting)
- : std::runtime_error ("Error in SubRip file: saw " + saw + " while expecting " + expecting)
- {}
+ SubripError (std::string saw, std::string expecting, std::list<std::string> context);
+
+ std::list<std::string> context () const {
+ return _context;
+ }
+
+private:
+ std::list<std::string> _context;
};
class MXFError : public std::runtime_error
diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc
index 94a48c0..6fab0ff 100644
--- a/src/subrip_reader.cc
+++ b/src/subrip_reader.cc
@@ -83,6 +83,12 @@ SubripReader::read (function<optional<string> ()> 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:
{
@@ -109,7 +115,13 @@ SubripReader::read (function<optional<string> ()> get_line)
boost::algorithm::split (p, *line, boost::algorithm::is_any_of (" "));
if (p.size() != 3 && p.size() != 7) {
- throw SubripError (*line, "a time/position line");
+ for (int i = 0; i < 2; ++i) {
+ optional<string> 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<string> 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<string> b;
diff --git a/src/subrip_reader.h b/src/subrip_reader.h
index 5f5f343..138d703 100644
--- a/src/subrip_reader.h
+++ b/src/subrip_reader.h
@@ -44,10 +44,12 @@ private:
friend struct ::subrip_reader_convert_time_test;
SubripReader () {}
- static Time convert_time (std::string t);
+ Time convert_time (std::string t);
void convert_line (std::string t, RawSubtitle& p);
void maybe_content (RawSubtitle& p);
void read (boost::function<boost::optional<std::string> ()> get_line);
+
+ std::list<std::string> _context;
};
}
diff --git a/src/wscript b/src/wscript
index 9136ea1..a22c712 100644
--- a/src/wscript
+++ b/src/wscript
@@ -49,6 +49,7 @@ def build(bld):
colour.h
dcp_reader.h
effect.h
+ exceptions.h
font_size.h
interop_dcp_reader.h
rational.h