Support unrar64.dll
[xy_vsfilter.git] / src / subtitles / RealTextParser.h
blob06247e43082a09060762190329df5463e04f913e
1 #pragma once
3 #include <sstream>
4 using std::wostream;
5 using std::wostringstream;
6 using std::endl;
8 #include <string>
9 using std::wstring;
11 #include <map>
12 using std::map;
13 using std::pair;
15 #include <vector>
16 using std::vector;
18 #include <list>
19 using std::list;
21 #include <cwctype>
22 using std::towlower;
24 class CRealTextParser
26 public:
27 CRealTextParser();
28 virtual ~CRealTextParser(void);
30 struct Tag
32 Tag(): m_bOpen(false), m_bClose(false), m_bComment(false), m_bText(false) {}
34 wstring m_szName;
36 bool m_bOpen;
37 bool m_bClose;
39 bool m_bComment;
40 bool m_bText;
42 map<wstring, wstring> m_mapAttributes;
45 struct Subtitles
47 Subtitles(): m_WindowTag(), m_FontTag(), m_bCenter(false) {}
49 Tag m_WindowTag;
50 Tag m_FontTag;
52 bool m_bCenter;
54 map<pair<int, int>, wstring> m_mapLines;
57 bool ParseRealText(wstring p_szFile);
59 const Subtitles& GetParsedSubtitles();
61 bool OutputSRT(wostream& p_rOutput);
63 private:
64 bool ExtractTag(wstring& p_rszLine, Tag& p_rTag);
65 bool ExtractTextTag(wstring& p_rszLine, Tag& p_rTag);
66 bool ExtractString(wstring& p_rszLine, wstring& p_rszString);
67 bool SkipSpaces(wstring& p_rszLine, unsigned int& p_riPos);
68 bool GetString(wstring& p_rszLine, unsigned int& p_riPos, wstring& p_rszString, const wstring& p_crszEndChars);
69 bool GetAttributes(wstring& p_rszLine, unsigned int& p_riPos, map<wstring, wstring>& p_rmapAttributes);
71 int GetTimecode(const wstring& p_crszTimecode);
72 wstring FormatTimecode(int iTimecode,
73 int iMillisecondPrecision = 3,
74 bool p_bPadZeroes = true,
75 const wstring& p_crszSeparator = L":",
76 const wstring& p_crszMillisecondSeparator = L".");
78 wstring StringToLower(const wstring& p_crszString);
80 wstring RenderTags(const list<Tag>& p_crlTags);
82 void PopTag(list<Tag>& p_rlistTags, const wstring& p_crszTagName);
84 // Filter out for example multiple font tags opened previously (font tags are not always terminated properly in realtext and can build up)
85 void FilterReduntantTags(list<Tag>& p_rlistTags);
88 Subtitles m_RealText;
90 bool m_bIgnoreFont;
91 bool m_bIgnoreFontSize;
92 bool m_bIgnoreFontColor;
93 bool m_bIgnoreFontWeight;
94 bool m_bIgnoreFontFace;
96 int m_iMinFontSize;
97 int m_iMaxFontSize;
99 int m_iDefaultSubtitleDurationInMillisecs;
101 bool m_bTryToIgnoreErrors;