#ifndef WEBVTT_WEBVTTPARSER_H_
#define WEBVTT_WEBVTTPARSER_H_
#include <list>
#include <string>
namespace libwebvtt {
class Reader {
public:
virtual int GetChar(char* c) = 0;
protected:
virtual ~Reader();
};
class LineReader : protected Reader {
public:
int GetLine(std::string* line);
protected:
virtual ~LineReader();
virtual void UngetChar(char c) = 0;
};
typedef long long presentation_t;
struct Time {
int hours;
int minutes;
int seconds;
int milliseconds;
bool operator==(const Time& rhs) const;
bool operator<(const Time& rhs) const;
bool operator>(const Time& rhs) const;
bool operator<=(const Time& rhs) const;
bool operator>=(const Time& rhs) const;
presentation_t presentation() const;
Time& presentation(presentation_t);
Time& operator+=(presentation_t);
Time operator+(presentation_t) const;
Time& operator-=(presentation_t);
presentation_t operator-(const Time&) const;
};
struct Setting {
std::string name;
std::string value;
};
struct Cue {
std::string identifier;
Time start_time;
Time stop_time;
typedef std::list<Setting> settings_t;
settings_t settings;
typedef std::list<std::string> payload_t;
payload_t payload;
};
class Parser : private LineReader {
public:
explicit Parser(Reader* r);
virtual ~Parser();
int Init();
int Parse(Cue* cue);
private:
virtual int GetChar(char* c);
virtual void UngetChar(char c);
int ParseBOM();
static int ParseTimingsLine(std::string* line,
std::string::size_type arrow_pos,
Time* start_time, Time* stop_time,
Cue::settings_t* settings);
static int ParseTime(const std::string& line, std::string::size_type* off,
Time* time);
static int ParseSettings(const std::string& line, std::string::size_type off,
Cue::settings_t* settings);
static int ParseNumber(const std::string& line, std::string::size_type* off);
Reader* const reader_;
int unget_;
Parser(const Parser&);
Parser& operator=(const Parser&);
};
}
#endif