interpolateComment method

String interpolateComment()

Replaces placeholders in comment with args

Implementation

String interpolateComment() {
  String interpolatedComment = '';
  if (comment != null) {
    interpolatedComment = comment!;
    var index = interpolatedComment.indexOf('{');
    while (index != -1) {
      var index2 = interpolatedComment.indexOf('}', index);
      var argPos = interpolatedComment.substring(index + 1, index2);
      String replacement = '?';
      try {
        replacement = args![int.parse(argPos) - 1];
      } catch (e) {
        throw Exception('cant interpolate comment');
      }
      interpolatedComment =
          interpolatedComment.replaceRange(index, index2 + 1, replacement);
      index = interpolatedComment.indexOf('{');
    }
  }
  return interpolatedComment;
}