unrollLoopPatternReplace method

String unrollLoopPatternReplace(
  1. String string
)

Implementation

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

  for (var match in matches) {
    var stringResult = '';

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

    for (var i = start; i < end; i++) {
      var 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;
}