isInvalidFilename function

bool isInvalidFilename(
  1. String filename
)

Implementation

bool isInvalidFilename(String filename) {
  /*
  sanitize-filename removes the following:
Control characters (0x00–0x1f and 0x80–0x9f)
Reserved characters (/, ?, <, >, \, :, *, |, and ")
Unix reserved filenames (. and ..)
Trailing periods and spaces (for Windows)
Windows reserved filenames (CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9)
 */
//[\/\?<>\\:\*\|"]
  var rg1 = RegExp(r'[\/\?<>\\:\*\|"]', multiLine: true);

  // forbidden characters  / : * ? " < > |
  // var rg2 = RegExp(r'^.'); // cannot start with dot (.)
  var rg3 = RegExp(r'^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$',
      caseSensitive: false, multiLine: true); //i; // forbidden file names

  //var result = false;
  //╟O
  if (filename.indexOf('╟') != -1) {
    print('╟O $filename');
    return true;
  }

  if (rg1.hasMatch(filename)) {
    print('rg1 $filename');
    return true;
  }
  if (rg3.hasMatch(filename)) {
    print('rg3 $filename');
    return true;
  }

  return false;
}