www.digitalmars.com Sargon Component Library for D


This module is used to manipulate path strings.

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

Boost License 1.0


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.

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

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

assert(buf.data == "file.ext");