www.digitalmars.com Sargon Component Library for D




sargon.path.setext

This module is used to manipulate path strings.

Authors:
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu

License:
Boost License 1.0

Source:
src/sargon/path/setext.d

auto setExt(R1, R2)(R1 path, R2 ext) if (isInputRange!R1 && isSomeChar!(ElementType!R1) && isInputRange!R2 && isSomeChar!(ElementType!R2));
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.

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

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

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