e29002f43a7e9e9b33235e51da92cc714c7e97cd
[libsub.git] / src / subrip_reader.h
1 /*
2     Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/subrip_reader.h
21  *  @brief SubripReader class.
22  */
23
24 #ifndef LIBSUB_SUBRIP_READER_H
25 #define LIBSUB_SUBRIP_READER_H
26
27 #include "reader.h"
28 #include <boost/function.hpp>
29 #include <list>
30
31 struct subrip_reader_convert_line_test;
32 struct subrip_reader_convert_time_test;
33 struct subrip_reader_test5;
34 struct subrip_reader_test6;
35
36 namespace sub {
37
38 class SubripReader : public Reader
39 {
40 public:
41         SubripReader (FILE* f);
42         SubripReader (std::string subs);
43
44         static boost::optional<Time> convert_time(std::string t, std::string* expected = nullptr);
45
46 private:
47         /* For tests */
48         friend struct ::subrip_reader_convert_line_test;
49         friend struct ::subrip_reader_convert_time_test;
50         friend struct ::subrip_reader_test5;
51         friend struct ::subrip_reader_test6;
52         SubripReader () {}
53
54         void convert_line (std::string t, RawSubtitle& p);
55         void maybe_content (RawSubtitle& p);
56         void read (boost::function<boost::optional<std::string> ()> get_line);
57
58         std::list<std::string> _context;
59 };
60
61 }
62
63 #endif