String module

path_ensure_extension

procedure · 1 overloadSource

path when its extension is already extension (without the dot); otherwise a new string with .extension added. Another extension is kept, so a.txt becomes a.txt.png.

path_ensure_extension :: (path: string, extension: string) -> string

The result is path itself in the first case, which the caller must not free; in the second it is allocated with the context allocator and the caller frees it.

Parameters

path: string
extension: string

Returns

string
ExampleOpen in playground ↗
same := path_ensure_extension("a.png", "png");
assert(same == "a.png");

longer := path_ensure_extension("a", "png");
defer free(longer);
assert(longer == "a.png");

See also