rStripTodo function

String rStripTodo(
  1. String code
)

From the supplied code (an R script file contents) strip any line that begins with # TODO so as not to expose such lines to the final script file.

Implementation

String rStripTodo(String code) {
  // Split the string into lines.

  List<String> lines = code.split('\n');

  List<String> filteredLines = lines
      // Filter out lines that start with optional whitespace followed by '#
      // TODO'.
      .where((line) => !RegExp(r'^\s*# TODO').hasMatch(line))
      // Filter out lines that start with optional whitespace followed by '##'
      // as markerts of things to be done and not included in the user scripts.
      .where((line) => !RegExp(r'^\s*##[^#]').hasMatch(line))
      .where((line) => !RegExp(r'^\s*##$').hasMatch(line))
      .toList();

  // Join the filtered lines back into a single string.

  String result = filteredLines.join('\n');

  return result;
}