withDefaultExtension

Set the extension of path to ext if path doesn't have one.

  1. auto withDefaultExtension(R path, C[] ext)
  2. auto withDefaultExtension(C1[] path, C2[] ext)
    withDefaultExtension
    (
    C1
    C2
    )
    (
    C1[] path
    ,
    C2[] ext
    )

Parameters

path C1[]

filespec as string or range

ext C2[]

extension, may have leading '.'

Return Value

Type: auto

range with the result

Examples

import std.array;
assert(withDefaultExtension("file", "ext").array == "file.ext");
assert(withDefaultExtension("file"w, ".ext").array == "file.ext"w);
assert(withDefaultExtension("file.", "ext").array == "file.");
assert(withDefaultExtension("file", "").array == "file.");

import std.utf : byChar, byWchar;
assert(withDefaultExtension("file".byChar, "ext").array == "file.ext");
assert(withDefaultExtension("file"w.byWchar, ".ext").array == "file.ext"w);
assert(withDefaultExtension("file.".byChar, "ext"d).array == "file.");
assert(withDefaultExtension("file".byChar, "").array == "file.");

Meta