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