withExtension method
Creates an Path like this but with the given extension.
Implementation
WindowsPath withExtension(String extension) {
final stem = fileStem().unwrapOr("");
final parentOption = parent();
if (parentOption.isNone()) {
if (stem.isEmpty) {
return WindowsPath(extension);
} else {
if (extension.isEmpty) {
return WindowsPath(stem);
}
return WindowsPath("$stem.$extension");
}
}
if (stem.isEmpty) {
return parentOption.unwrap().join(WindowsPath(extension));
}
if (extension.isEmpty) {
return parentOption.unwrap().join(WindowsPath(stem));
}
return parentOption.unwrap().join(WindowsPath("$stem.$extension"));
}