escapedPath

Replaces some invalid filenames to something that can be stored on the filesystem.

This is really only a problem on Windows, as the Posix dirSeparator is not a valid IRC character, nor does it have special legacy filenames like NUL and CON.

version(WithPrinterPlugin)
package
escapedPath
(
string path
)

Parameters

path string

A filesystem path in string form.

Return Value

Type: auto

The passed path with some characters potentially added or replaced. The original string is returned as-was if nothing no changes were needed.

Examples

version(Windows)
{
    {
        immutable before = "a\\b";
        immutable after = escapedPath(before);
        immutable expected = "a~b";
        assert((after == expected), after);
    }
    {
        immutable before = "CON";
        immutable after = escapedPath(before);
        immutable expected = "CON~";
        assert((after == expected), after);
    }
    {
        immutable before = "NUL";
        immutable after = escapedPath(before);
        immutable expected = "NUL~";
        assert((after == expected), after);
    }
    {
        immutable before = "aUx";
        immutable after = escapedPath(before);
        immutable expected = "aUx~";
        assert((after == expected), after);
    }
    {
        immutable before = "con-";
        immutable after = escapedPath(before);
        assert((after is before), after);
    }
    {
        immutable before = "con|";
        immutable after = escapedPath(before);
        immutable expected = "con)";
        assert((after == expected), after);
    }
}
else version(Posix)
{
    immutable before = "passthrough";
    immutable after = escapedPath(before);
    assert((after is before), after);
}