fromPgn static method

PgnCommentShape? fromPgn(
  1. String str
)

Parse the PGN for any comment or return null.

Implementation

static PgnCommentShape? fromPgn(String str) {
  final color = CommentShapeColor.parseShapeColor(str.substring(0, 1));
  final from = Square.parse(str.substring(1, 3));
  if (color == null || from == null) return null;
  if (str.length == 3) {
    return PgnCommentShape(color: color, from: from, to: from);
  }
  final to = Square.parse(str.substring(3, 5));
  if (str.length == 5 && to != null) {
    return PgnCommentShape(color: color, from: from, to: to);
  }
  return null;
}