Direction.fromSquareName constructor

Direction.fromSquareName(
  1. String name
)

Implementation

factory Direction.fromSquareName(String name) {
  name = name.toLowerCase();
  RegExp rx = RegExp(r'([A-Za-z])([0-9]+)');
  RegExpMatch? match = rx.firstMatch(name);
  assert(match != null, 'Invalid square name: $name');
  assert(match!.groupCount == 2, 'Invalid square name: $name');
  String file = match!.group(1)!;
  String rank = match.group(2)!;
  int fileNum = file.codeUnits[0] - Bishop.asciiA;
  int rankNum = int.parse(rank) - 1;
  return Direction(fileNum, rankNum);
}