Fix isAbsolutePathInternal for string_view

This commit is contained in:
halx99 2021-12-31 15:50:34 +08:00
parent deddc5542e
commit 85f1f0b424
1 changed files with 5 additions and 4 deletions

View File

@ -1053,16 +1053,17 @@ bool FileUtils::isAbsolutePath(std::string_view path) const
bool FileUtils::isAbsolutePathInternal(std::string_view path)
{
const char* raw = path.data();
#if defined(_WIN32)
// see also: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN
return ((path.length() > 2 && ((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z')) &&
path[1] == ':') // Normal absolute path
return ((path.length() > 2 && ((raw[0] >= 'a' && raw[0] <= 'z') || (raw[0] >= 'A' && raw[0] <= 'Z')) &&
raw[1] == ':') // Normal absolute path
|| cxx20::starts_with(path, R"(\\?\)") // Win32 File Namespaces for Long Path
|| cxx20::starts_with(path, R"(\\.\)") // Win32 Device Namespaces for device
|| (path[0] == '/' || path[0] == '\\') // Current disk drive
|| (raw[0] == '/' || raw[0] == '\\') // Current disk drive
);
#else
return (path[0] == '/');
return (raw[0] == '/');
#endif
}