MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / parse

Method parse

Libs/srtparser/srtparser.h:198–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198inline void SubRipParser::parse(std::string fileName) //srt parser
199{
200
201 std::ifstream infile(fileName);
202 std::string line, start, end, completeLine = "", timeLine = "";
203 int subNo, turn = 0;
204
205 /*
206 * turn = 0 -> Add subtitle number
207 * turn = 1 -> Add string to timeLine
208 * turn > 1 -> Add string to completeLine
209 */
210
211 while (std::getline(infile, line))
212 {
213 line.erase(remove(line.begin(), line.end(), '\r'), line.end());
214
215 if (line.compare(""))
216 {
217 if(!turn)
218 {
219 subNo=atoi(line.c_str());
220 turn++;
221 continue;
222 }
223
224 if (line.find("-->") != std::string::npos)
225 {
226 timeLine += line;
227
228 std::vector<std::string> srtTime;
229 srtTime = split(timeLine, ' ', srtTime);
230 start = srtTime[0];
231 end = srtTime[2];
232
233 }
234 else
235 {
236 if (completeLine != "")
237 completeLine += "\n";
238
239 completeLine += line;
240 }
241
242 turn++;
243 }
244
245 else
246 {
247 turn = 0;
248 _subtitles.push_back(new SubtitleItem(subNo,start,end,completeLine));
249 completeLine = timeLine = "";
250 }
251
252 if(infile.eof()) //insert last remaining subtitle
253 {
254 _subtitles.push_back(new SubtitleItem(subNo,start,end,completeLine));
255 }

Callers

nothing calls this directly

Calls 8

removeFunction · 0.85
compareMethod · 0.80
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
c_strMethod · 0.45
findMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected