summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2022-04-16 02:01:24 +0200
committerAdmiral H. Curtiss <pikachu025@gmail.com>2022-06-05 21:24:45 +0200
commitb1d1f2aa06f4bf7d0a7f5a151c285a0fea0db965 (patch)
treee01650f495e547dc0ddae4084f43dd6a0aa72bd1 /Source/Core/Common
parent2081e2f2a19e8216c5292c30083a20b38236e8bc (diff)
Common/StringUtil: Add convenience function for converting paths to use forward slashes on Windows.
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/StringUtil.cpp17
-rw-r--r--Source/Core/Common/StringUtil.h8
2 files changed, 25 insertions, 0 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp
index a752ab0e10..c498e261fd 100644
--- a/Source/Core/Common/StringUtil.cpp
+++ b/Source/Core/Common/StringUtil.cpp
@@ -335,6 +335,23 @@ bool SplitPath(std::string_view full_path, std::string* path, std::string* filen
return true;
}
+void UnifyPathSeparators(std::string& path)
+{
+#ifdef _WIN32
+ for (char& c : path)
+ {
+ if (c == '\\')
+ c = '/';
+ }
+#endif
+}
+
+std::string WithUnifiedPathSeparators(std::string path)
+{
+ UnifyPathSeparators(path);
+ return path;
+}
+
std::string PathToFileName(std::string_view path)
{
std::string file_name, extension;
diff --git a/Source/Core/Common/StringUtil.h b/Source/Core/Common/StringUtil.h
index 56fa756a46..5db7cbfa37 100644
--- a/Source/Core/Common/StringUtil.h
+++ b/Source/Core/Common/StringUtil.h
@@ -157,9 +157,17 @@ std::vector<std::string> SplitString(const std::string& str, char delim);
std::string JoinStrings(const std::vector<std::string>& strings, const std::string& delimiter);
// "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe"
+// This requires forward slashes to be used for the path separators, even on Windows.
bool SplitPath(std::string_view full_path, std::string* path, std::string* filename,
std::string* extension);
+// Converts the path separators of a path into forward slashes on Windows, which is assumed to be
+// true for paths at various places in the codebase.
+void UnifyPathSeparators(std::string& path);
+std::string WithUnifiedPathSeparators(std::string path);
+
+// Extracts just the filename (including extension) from a full path.
+// This requires forward slashes to be used for the path separators, even on Windows.
std::string PathToFileName(std::string_view path);
bool StringBeginsWith(std::string_view str, std::string_view begin);