Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Parsing JacoSub (subtitle edit)
- private struct ParseData
- {
- public TimeSpan StartTime { get; set; }
- public TimeSpan EndTime { get; set; }
- }
- Paragraph Paragraph(string line)
- {
- return StartTime(line, 0);
- }
- Paragraph StartTime(string line, int position)
- {
- var parseData = new ParseData();
- // H:MM:SS.FF H:MM:SS.FF directive {comment} text {comment} more text...
- if (position + 10 < line.Length)
- {
- var timestamp = line.Substring(position, 10);
- parseData.StartTime = TimeSpan.ParseExact(timestamp, "H:MM:SS.FF", CultureInfo.CurrentCulture);
- return EndTime(line, position + 10, ref parseData); // read the time cod from 10 index
- }
- return null;
- }
- Paragraph EndTime(string line, int position, ref ParseData parseData)
- {
- // H:MM:SS.FF H:MM:SS.FF directive {comment} text {comment} more text...
- while (position < line.Length && line[position] == ' ') position++;
- if (position + 10 < line.Length)
- {
- var timestamp = line.Substring(position, 10);
- parseData.EndTime = TimeSpan.ParseExact(timestamp, "H:MM:SS.FF", CultureInfo.CurrentCulture);
- return EndTime(line, position + 10, ref parseData); // read the time cod from 10 index
- }
- return null;
- }
- Paragraph Text(string line, int position, ref ParseData token)
- {
- // H:MM:SS.FF H:MM:SS.FF directive {comment} text {comment} more text...
- if (position + 1 < line.Length)
- {
- return new Paragraph()
- {
- StartTime = new TimeCode(token.StartTime.TotalMilliseconds),
- EndTime = new TimeCode(token.EndTime.TotalMilliseconds),
- Text = line.Substring(position).TrimStart()
- };
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement