defaultExtension

immutable(C1)[]
defaultExtension
(
C1
C2
)
(
in C1[] path
,
in C2[] ext
)
if (
isSomeChar!C1 &&
is(immutable C1 == immutable C2)
)

Parameters

path C1[]

A path name.

ext C2[]

The default extension to use.

Return Value

Type: immutable(C1)[]

The path given by path, with the extension given by ext appended if the path doesn't already have one.

Including the dot in the extension is optional.

This function always allocates a new string, except in the case when path is immutable and already has an extension.

Examples

assert(defaultExtension("file", "ext") == "file.ext");
assert(defaultExtension("file", ".ext") == "file.ext");
assert(defaultExtension("file.", "ext")     == "file.");
assert(defaultExtension("file.old", "new") == "file.old");
assert(defaultExtension("file.old", ".new") == "file.old");

Meta