diff options
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) { | |||
| 826 | } | 826 | } |
| 827 | 827 | ||
| 828 | while (path[0] == '\\' || path[0] == '/') { | 828 | while (path[0] == '\\' || path[0] == '/') { |
| 829 | path.remove_suffix(1); | 829 | path.remove_prefix(1); |
| 830 | if (path.empty()) { | 830 | if (path.empty()) { |
| 831 | return path; | 831 | return path; |
| 832 | } | 832 | } |
| @@ -870,6 +870,15 @@ std::string_view RemoveTrailingSlash(std::string_view path) { | |||
| 870 | return path; | 870 | return path; |
| 871 | } | 871 | } |
| 872 | 872 | ||
| 873 | std::string SanitizePath(std::string_view path_) { | ||
| 874 | std::string path(path_); | ||
| 875 | std::replace(path.begin(), path.end(), '\\', '/'); | ||
| 876 | path.erase(std::unique(path.begin(), path.end(), | ||
| 877 | [](char c1, char c2) { return c1 == '/' && c2 == '/'; }), | ||
| 878 | path.end()); | ||
| 879 | return std::string(RemoveTrailingSlash(path)); | ||
| 880 | } | ||
| 881 | |||
| 873 | IOFile::IOFile() {} | 882 | IOFile::IOFile() {} |
| 874 | 883 | ||
| 875 | IOFile::IOFile(const std::string& filename, const char openmode[], int flags) { | 884 | 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 | |||
| 178 | return std::vector<T>(vector.begin() + first, vector.begin() + first + last); | 178 | return std::vector<T>(vector.begin() + first, vector.begin() + first + last); |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | // Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. | ||
| 182 | std::string SanitizePath(std::string_view path); | ||
| 183 | |||
| 181 | // simple wrapper for cstdlib file functions to | 184 | // simple wrapper for cstdlib file functions to |
| 182 | // hopefully will make error checking easier | 185 | // hopefully will make error checking easier |
| 183 | // and make forgetting an fclose() harder | 186 | // and make forgetting an fclose() harder |