Algorithm.parse constructor

Algorithm.parse(
  1. String text
)

Parses an Algorithm from String.

Implementation

factory Algorithm.parse(String text) {
  const ignoreChars = ' ()[]';
  final moves = <Move>[];

  for (var i = 0; i < text.length; i++) {
    final c = text[i];

    if (ignoreChars.contains(c)) continue;

    if (i + 1 < text.length && (text[i + 1] == "'" || text[i + 1] == '2')) {
      moves.add(Move.parse(c + text[++i]));
    } else {
      moves.add(Move.parse(c));
    }
  }

  return Algorithm(moves: moves);
}