sterilizePath static method
Removes illegal characters from the givin filePath
.
It also cleans the filePath
with cleanPath.
Implementation
static String sterilizePath(String filePath) {
final List<String> illegalChars = _illegalPathChars + _illegalChars;
String filePathSterile = filePath;
for (String char in illegalChars) {
filePathSterile = filePathSterile.replaceAll(char, "");
}
// Remove double path separators.
while (filePathSterile
.contains("${Platform.pathSeparator}${Platform.pathSeparator}")) {
filePathSterile.replaceAll(
"${Platform.pathSeparator}${Platform.pathSeparator}",
Platform.pathSeparator);
}
// Remove improper leading chars.
while (filePathSterile.startsWith("~") || filePathSterile.startsWith("-")) {
if (filePathSterile.length > 1) {
filePathSterile = filePathSterile.substring(1);
} else {
filePathSterile = "";
break;
}
}
return filePathSterile;
}