View source code
Display the source code in dmd/utils.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function dmd.utils.toPosixPath
Normalize path by turning backslashes into forward slashes
const(char)* toPosixPath
(
const(char)* src
) nothrow @trusted;
const(char)[] toPosixPath
(
const(char)[] src
) pure nothrow @safe;
Parameters
Name | Description |
---|---|
src | Source path, using window-style ('\') or mixed path separators |
Returns
A newly-allocated string with '\' turned into '/'
Example
const(char)[] nullStr;
const(char)* nullStrP;
writeln(toPosixPath(nullStrP)); // null
writeln(toPosixPath(nullStr)); // null
@trusted nothrow void assertion(const(char)[] s1, const(char)[] s2)
{
writeln(toPosixPath(s1)); // s2
writeln(strcmp(toPosixPath(s1 .ptr), s2 .ptr)); // 0
}
const posixAbsPath = `/some/path`;
const posixRelPath = `some/path`;
const windowsAbsPath = `C:\some\path`;
const windowsAbsMixedPath = `C:\some/path`;
const windowsAbsPosixPath = `C:/some/path`;
const windowsRelPath = `some\path`;
assertion(posixAbsPath, posixAbsPath);
assertion(posixRelPath, posixRelPath);
assertion(windowsAbsPath, windowsAbsPosixPath);
assertion(windowsAbsMixedPath, windowsAbsPosixPath);
assertion(windowsAbsPosixPath, windowsAbsPosixPath);
assertion(windowsRelPath, posixRelPath);
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.