parseCoordinates function
Implementation
@visibleForTesting
void parseCoordinates(Subtitle subtitle, String chunk1) {
final RegExp detectCoordination = RegExp(r'((X|Y)(\d)):(\d\d\d)');
final Iterable<Match> result = detectCoordination.allMatches(chunk1);
if (result.length != 0) {
List listOfXs =
result.where((Match match) => match.group(2) == 'X').toList();
//divide by 2 and create a Coordination of each X:Y group
for (Match item in listOfXs) {
int number = int.parse(item.group(3)!);
Match matchingY = result.firstWhere((Match matchY) {
return (matchY.group(2) == 'Y' && int.parse(matchY.group(3)!) == number);
});
Line parsedLine = Line(subtitle.rawLines[listOfXs.indexOf(item)]);
parsedLine.coordinates = Coordinates(
x: int.parse(item.group(4)!), y: int.parse(matchingY.group(4)!));
subtitle.parsedLines.add(parsedLine);
}
} else {
for (String line in subtitle.rawLines) {
Line parsedLine = Line(line);
subtitle.parsedLines.add(parsedLine);
}
}
}