fswToSign function

Sign fswToSign(
  1. String fsw
)

Implementation

Sign fswToSign(String fsw) {
  // Regular expression to match the box notation in FSW
  RegExp boxesRegex = RegExp(r'([BLMR])(\d{3})x(\d{3})');
  Iterable<Match> boxes = boxesRegex.allMatches(fsw);
  Match? box = boxes.isNotEmpty ? boxes.first : null;

  // Extracting box symbol, x-coordinate, and y-coordinate
  String boxSymbol = box != null ? box.group(1)! : "M";
  String x = box != null ? box.group(2)! : "500";
  String y = box != null ? box.group(3)! : "500";

  // Regular expression to match symbols and their positions in FSW
  RegExp symbolsRegex =
      RegExp(r'(S[123][0-9a-f]{2}[0-5][0-9a-f])(\d{3})x(\d{3})');
  Iterable<Match> symbols = symbolsRegex.allMatches(fsw);

  // Parsing symbols and their positions
  List<SignSymbol> parsedSymbols = [];
  for (Match s in symbols) {
    String symbol = s.group(1)!;
    String posX = s.group(2)!;
    String posY = s.group(3)!;
    parsedSymbols.add(
      SignSymbol(
          symbol: symbol,
          position:
              Tuple2<int, int>.fromList([int.parse(posX), int.parse(posY)])),
    );
  }

  // Creating and returning a Sign object
  return Sign(
    box: SignSymbol(
        symbol: boxSymbol,
        position: Tuple2<int, int>.fromList([int.parse(x), int.parse(y)])),
    symbols: parsedSymbols,
  );
}