validatePath method
Check if the given path is correct.
If the path wasn't correct it will correct it and return a god one
- returns null if null or empty path was given
Implementation
String? validatePath(String? path) {
if (path != null && path.isNotEmpty) {
StringBuffer validPath = StringBuffer();
int len = path.length;
if (!path.startsWith('/') && !Platform.isWindows) {
validPath.write("/");
len++;
}
if (path.endsWith('/') || path.endsWith('\\')) {
validPath.write(path.substring(0, len - 2));
} else {
validPath.write(path);
}
return validPath.toString().replaceAll(RegExp(r"[/\\]+"), pathJoin);
}
return null;
}