Commit a714936e authored by Kenton Varda's avatar Kenton Varda

Add evalNative() / toNativeString() helpers to Path.

These use Win32 variants if and only if compiling for Windows.
parent 47e755eb
......@@ -171,6 +171,12 @@ public:
// the colon, will become the first component of the path, e.g. "c:\foo" becomes {"c:", "foo"}.
// - A network path like "\\host\share\path" is parsed as {"host", "share", "path"}.
Path evalNative(StringPtr pathText) const&;
Path evalNative(StringPtr pathText) &&;
// Alias for either eval() or evalWin32() depending on the target platform. Use this when you are
// parsing a path provided by a user and you want the user to be able to use the "natural" format
// for their platform.
String toWin32String(bool absolute = false) const;
// Converts the path to a Win32 path string, as you might display to a user.
//
......@@ -184,6 +190,11 @@ public:
// Windows, such as if it contains backslashes (within a path component), colons, or special
// names like "con".
String toNativeString(bool absolute = false) const;
// Alias for either toString() or toWin32String() depending on the target platform. Use this when
// you are formatting a path to display to a user and you want to present it in the "natural"
// format for the user's platform.
Array<wchar_t> forWin32Api(bool absolute) const;
// Like toWin32String, but additionally:
// - Converts the path to UTF-16, with a NUL terminator included.
......@@ -257,7 +268,9 @@ public:
bool startsWith(PathPtr prefix) const;
bool endsWith(PathPtr suffix) const;
Path evalWin32(StringPtr pathText) const;
Path evalNative(StringPtr pathText) const;
String toWin32String(bool absolute = false) const;
String toNativeString(bool absolute = false) const;
Array<wchar_t> forWin32Api(bool absolute) const;
// Equivalent to the corresponding methods of `Path`.
......@@ -986,6 +999,40 @@ inline String PathPtr::toWin32String(bool absolute) const {
return toWin32StringImpl(absolute, false);
}
#if _WIN32
inline Path Path::evalNative(StringPtr pathText) const& {
return evalWin32(pathText);
}
inline Path Path::evalNative(StringPtr pathText) && {
return kj::mv(*this).evalWin32(pathText);
}
inline String Path::toNativeString(bool absolute) const {
return toWin32String(absolute);
}
inline Path PathPtr::evalNative(StringPtr pathText) const {
return evalWin32(pathText);
}
inline String PathPtr::toNativeString(bool absolute) const {
return toWin32String(absolute);
}
#else
inline Path Path::evalNative(StringPtr pathText) const& {
return eval(pathText);
}
inline Path Path::evalNative(StringPtr pathText) && {
return kj::mv(*this).eval(pathText);
}
inline String Path::toNativeString(bool absolute) const {
return toString(absolute);
}
inline Path PathPtr::evalNative(StringPtr pathText) const {
return eval(pathText);
}
inline String PathPtr::toNativeString(bool absolute) const {
return toString(absolute);
}
#endif // _WIN32, else
inline Own<FsNode> FsNode::clone() { return cloneFsNode().downcast<FsNode>(); }
inline Own<ReadableFile> ReadableFile::clone() { return cloneFsNode().downcast<ReadableFile>(); }
inline Own<AppendableFile> AppendableFile::clone() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment