/*
- 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
#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)
{
}
+
+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)
+{
+
+}
/*
- 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
#include <stdexcept>
#include <string>
+#include <list>
namespace sub {
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
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:
{
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]);
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;
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;
};
}
colour.h
dcp_reader.h
effect.h
+ exceptions.h
font_size.h
interop_dcp_reader.h
rational.h
/** Test SubripReader::convert_time */
BOOST_AUTO_TEST_CASE (subrip_reader_convert_time_test)
{
- BOOST_CHECK_EQUAL (sub::SubripReader::convert_time ("00:03:10,500"), sub::Time::from_hms (0, 3, 10, 500));
- BOOST_CHECK_EQUAL (sub::SubripReader::convert_time ("04:19:51,782"), sub::Time::from_hms (4, 19, 51, 782));
+ sub::SubripReader reader;
+ BOOST_CHECK_EQUAL (reader.convert_time ("00:03:10,500"), sub::Time::from_hms (0, 3, 10, 500));
+ BOOST_CHECK_EQUAL (reader.convert_time ("04:19:51,782"), sub::Time::from_hms (4, 19, 51, 782));
}
static void