chainPath

Concatenate path segments together to form one path.

chainPath
(
R1
R2
Ranges...
)
(
R1 r1
,
R2 r2
,
Ranges ranges
)
if (
(
isRandomAccessRange!R1 &&
hasSlicing!R1
&&
hasLength!R1
&&
isSomeChar!(ElementType!R1)
||
)
&&
(
isRandomAccessRange!R2 &&
hasSlicing!R2
&&
hasLength!R2
&&
isSomeChar!(ElementType!R2)
||
)
&&
(
Ranges.length == 0 ||
is(typeof(chainPath(r2, ranges)))
)
)

Parameters

r1 R1

first segment

r2 R2

second segment

ranges Ranges

0 or more segments

Return Value

Type: auto

Lazy range which is the concatenation of r1, r2 and ranges with path separators. The resulting element type is that of r1.

Examples

import std.array;
version (Posix)
{
    assert(chainPath("foo", "bar", "baz").array == "foo/bar/baz");
    assert(chainPath("/foo/", "bar/baz").array  == "/foo/bar/baz");
    assert(chainPath("/foo", "/bar").array      == "/bar");
}

version (Windows)
{
    assert(chainPath("foo", "bar", "baz").array == `foo\bar\baz`);
    assert(chainPath(`c:\foo`, `bar\baz`).array == `c:\foo\bar\baz`);
    assert(chainPath("foo", `d:\bar`).array     == `d:\bar`);
    assert(chainPath("foo", `\bar`).array       == `\bar`);
    assert(chainPath(`c:\foo`, `\bar`).array    == `c:\bar`);
}

import std.utf : byChar;
version (Posix)
{
    assert(chainPath("foo", "bar", "baz").array == "foo/bar/baz");
    assert(chainPath("/foo/".byChar, "bar/baz").array  == "/foo/bar/baz");
    assert(chainPath("/foo", "/bar".byChar).array      == "/bar");
}

version (Windows)
{
    assert(chainPath("foo", "bar", "baz").array == `foo\bar\baz`);
    assert(chainPath(`c:\foo`.byChar, `bar\baz`).array == `c:\foo\bar\baz`);
    assert(chainPath("foo", `d:\bar`).array     == `d:\bar`);
    assert(chainPath("foo", `\bar`.byChar).array       == `\bar`);
    assert(chainPath(`c:\foo`, `\bar`w).array    == `c:\bar`);
}

See Also

Meta