-
Notifications
You must be signed in to change notification settings - Fork 6
/
SubtitleParserFactory.cpp
60 lines (54 loc) · 1.06 KB
/
SubtitleParserFactory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <vector>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include "SubtitleParser.h"
#include "SubRipParser.h"
#include "SubtitleParserFactory.h"
SubtitleParserFactory::SubtitleParserFactory(std::string fileName)
{
_fileName = fileName;
_subFormat = checkSubtitleFormat(fileName);
}
SubtitleFormat SubtitleParserFactory::checkSubtitleFormat(std::string fileName)
{
if(fileName.size()<5) return UndefinedType;
std::string format = fileName.substr(fileName.size()-4,fileName.size());
if(format == ".srt")
{
return SubRip;
}
else if(format == ".sub")
{
return MicroDvd;
}
else if(format == ".vtt")
{
return WebVtt;
}
else
{
return UndefinedType;
}
}
SubtitleParser* SubtitleParserFactory::getParser()
{
switch(_subFormat)
{
case SubRip:
{
return new SubRipParser(_fileName);
}
break;
default:
{
std::cout<<"Error: Undefined subtitle format!";
throw std::exception();
}
}
throw std::exception();
}
SubtitleParserFactory::~SubtitleParserFactory(void)
{
}