diff options
author | Zach Hilman <DarkLordZach@users.noreply.github.com> | 2018-07-24 04:40:35 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-07-24 04:40:35 +0200 |
commit | 59cb258409c5cbd6cdc9cc6a6f8e858603924a2b (patch) | |
tree | c024d285fe63daae9d73ef07800349a065768672 /src/common | |
parent | Merge pull request #787 from bunnei/tlds (diff) | |
download | yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.tar yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.tar.gz yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.tar.bz2 yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.tar.lz yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.tar.xz yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.tar.zst yuzu-59cb258409c5cbd6cdc9cc6a6f8e858603924a2b.zip |
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/file_util.cpp | 11 | ||||
-rw-r--r-- | src/common/file_util.h | 3 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 1bc291cf9..b8dd92b65 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -826,7 +826,7 @@ std::string_view GetPathWithoutTop(std::string_view path) { } while (path[0] == '\\' || path[0] == '/') { - path.remove_suffix(1); + path.remove_prefix(1); if (path.empty()) { return path; } @@ -870,6 +870,15 @@ std::string_view RemoveTrailingSlash(std::string_view path) { return path; } +std::string SanitizePath(std::string_view path_) { + std::string path(path_); + std::replace(path.begin(), path.end(), '\\', '/'); + path.erase(std::unique(path.begin(), path.end(), + [](char c1, char c2) { return c1 == '/' && c2 == '/'; }), + path.end()); + return std::string(RemoveTrailingSlash(path)); +} + IOFile::IOFile() {} IOFile::IOFile(const std::string& filename, const char openmode[], int flags) { diff --git a/src/common/file_util.h b/src/common/file_util.h index abfa79eae..bc9272d89 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -178,6 +178,9 @@ std::vector<T> SliceVector(const std::vector<T>& vector, size_t first, size_t la return std::vector<T>(vector.begin() + first, vector.begin() + first + last); } +// Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. +std::string SanitizePath(std::string_view path); + // simple wrapper for cstdlib file functions to // hopefully will make error checking easier // and make forgetting an fclose() harder |