mirror of https://github.com/PCSX2/pcsx2.git
FileSystem: Add path splitting helpers
This commit is contained in:
parent
6991f819f3
commit
a635e84d82
|
@ -214,6 +214,39 @@ std::string_view FileSystem::GetFileTitleFromPath(const std::string_view& path)
|
|||
return filename.substr(0, pos);
|
||||
}
|
||||
|
||||
std::vector<std::string_view> FileSystem::SplitWindowsPath(const std::string_view& path)
|
||||
{
|
||||
std::vector<std::string_view> parts;
|
||||
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type pos = 0;
|
||||
while (pos < path.size())
|
||||
{
|
||||
if (path[pos] != '/' && path[pos] != '\\')
|
||||
{
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip consecutive separators
|
||||
if (pos != start)
|
||||
parts.push_back(path.substr(start, pos - start));
|
||||
|
||||
pos++;
|
||||
start = pos;
|
||||
}
|
||||
|
||||
if (start != pos)
|
||||
parts.push_back(path.substr(start));
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> FileSystem::SplitNativePath(const std::string_view& path)
|
||||
{
|
||||
return StringUtil::SplitString(path, FS_OSPATH_SEPARATOR_CHARACTER, true);
|
||||
}
|
||||
|
||||
std::vector<std::string> FileSystem::GetRootDirectoryList()
|
||||
{
|
||||
std::vector<std::string> results;
|
||||
|
|
|
@ -102,6 +102,12 @@ namespace FileSystem
|
|||
/// Returns the file title (less the extension and path) from a filename.
|
||||
std::string_view GetFileTitleFromPath(const std::string_view& path);
|
||||
|
||||
/// Splits a path into its components, handling both Windows and Unix separators.
|
||||
std::vector<std::string_view> SplitWindowsPath(const std::string_view& path);
|
||||
|
||||
/// Splits a path into its components, only handling native separators.
|
||||
std::vector<std::string_view> SplitNativePath(const std::string_view& path);
|
||||
|
||||
/// Returns a list of "root directories" (i.e. root/home directories on Linux, drive letters on Windows).
|
||||
std::vector<std::string> GetRootDirectoryList();
|
||||
|
||||
|
|
Loading…
Reference in New Issue