unrollLoopPatternReplace method

String unrollLoopPatternReplace(
  1. String string
)

Implementation

String unrollLoopPatternReplace(String string) {
  final matches = unrollLoopPattern.allMatches(string);

  for (final match in matches) {
    String stringResult = '';

    int start = int.parse(match.group(1)!);
    int end = int.parse(match.group(2)!);
    final snippet = match.group(3)!;

    for (int i = start; i < end; i++) {
      String snippet2 = snippet.replaceAll(RegExp(r"\[\s*i\s*\]"), "[$i]");
      snippet2 = snippet2.replaceAll(RegExp(r"UNROLLED_LOOP_INDEX"), i.toString());
      // string += snippet
      //   .replace( /\[\s*i\s*\]/g, '[ ' + i + ' ]' )
      //   .replace( /UNROLLED_LOOP_INDEX/g, i );

      stringResult = stringResult + snippet2;
    }

    string = string.replaceFirst(match.group(0)!, stringResult);
  }

  // print(string);
  // if(match != null) {
  //   print(" unrollLoopPatternReplace  match start: ${match.start} end: ${match.end} ");

  // } else {
  //   print("unrollLoopPatternReplace match is null  ");
  // }

  return string;
}