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