The OpenD Programming Language

isAbsolute

Determines whether a path is absolute or not.

version(StdDdoc)
pure nothrow @safe
bool
isAbsolute
(
R
)
()
if (
is(StringTypeOf!R)
)

Return Value

Type: bool

Whether a path is absolute or not.

Examples

On POSIX, an absolute path starts at the root directory. (In fact, _isAbsolute is just an alias for isRooted.)

version (Posix)
{
    assert(isAbsolute("/"));
    assert(isAbsolute("/foo"));
    assert(!isAbsolute("foo"));
    assert(!isAbsolute("../foo"));
}

On Windows, an absolute path starts at the root directory of a specific drive. Hence, it must start with `d:\` or `d:/`, where d is the drive letter. Alternatively, it may be a network path, i.e. a path starting with a double (back)slash.

version (Windows)
{
    assert(isAbsolute(`d:\`));
    assert(isAbsolute(`d:\foo`));
    assert(isAbsolute(`\\foo\bar`));
    assert(!isAbsolute(`\`));
    assert(!isAbsolute(`\foo`));
    assert(!isAbsolute("d:foo"));
}

Meta