stripExt

Returns slice of path[] with the extension stripped off.

stripExt is an algorithm that does not allocate nor throw, it is pure and @safe.

stripExt
(
R
)
()

Parameters

path R

a RandomAccessRange that can be sliced.

Return Value

Type: auto

a slice of path

Examples

assert (stripExt("file")           == "file");
assert (stripExt("file.ext")       == "file");
assert (stripExt("file.ext1.ext2") == "file.ext1");
assert (stripExt("file.")          == "file");
assert (stripExt(".file")          == ".file");
assert (stripExt(".file.ext")      == ".file");
assert (stripExt("dir/file.ext")   == "dir/file");

{
    import std.internal.scopebuffer;

    char[10] tmpbuf = void;
    auto buf = ScopeBuffer!char(tmpbuf);
    scope(exit) buf.free();

    buf.length = 0;
    "file.ext".byChar().stripExt().copy(&buf);
    assert(buf[] == "file");
}

Meta