setExt

Algorithm that accepts a _path as an InputRange and a file extension as an InputRange, and returns an InputRange that produces a char string containing the _path given by path, but where the extension has been set to ext.

If the filename already has an extension, it is replaced. If not, the extension is simply appended to the filename. Including a leading dot in ext is optional.

If the extension is empty, this function produces the equivalent of stripExtension applied to path.

The algorithm is lazy, does not allocate, does not throw, and is pure.

setExt
(
R1
R2
)
(
R1 path
,
R2 ext
)
if (
isInputRange!R1 &&
isSomeChar!(ElementType!R1)
&&
isInputRange!R2
&&
isSomeChar!(ElementType!R2)
)

Examples

import std.algorithm : copy;
import std.array : appender;

auto buf = appender!(char[])();

"file".setExt("ext").copy(&buf);
assert(buf.data == "file.ext");

Meta