parseBeginEnd function
Implementation
@visibleForTesting
Range? parseBeginEnd(String line) {
final RegExp pattern = RegExp(
r'(\d\d):(\d\d):(\d\d),(\d\d\d) --> (\d\d):(\d\d):(\d\d),(\d\d\d)');
final Match match = pattern.firstMatch(line)!;
if (match == null) {
return null;
} else if (int.parse(match.group(1)!) > 23 ||
int.parse(match.group(2)!) > 59 ||
int.parse(match.group(3)!) > 59 ||
int.parse(match.group(4)!) > 999 ||
int.parse(match.group(5)!) > 23 ||
int.parse(match.group(6)!) > 59 ||
int.parse(match.group(7)!) > 59 ||
int.parse(match.group(8)!) > 999) {
throw RangeError(
'time components are out of range. Please modify the .srt file.');
} else {
final int begin = timeStampToMillis(
int.parse(match.group(1)!),
int.parse(match.group(2)!),
int.parse(match.group(3)!),
int.parse(match.group(4)!));
final int end = timeStampToMillis(
int.parse(match.group(5)!),
int.parse(match.group(6)!),
int.parse(match.group(7)!),
int.parse(match.group(8)!));
return Range(begin, end);
}
}