summaryrefslogtreecommitdiff
path: root/src/common/fs/fs_util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/fs/fs_util.cpp')
-rw-r--r--src/common/fs/fs_util.cpp59
1 files changed, 0 insertions, 59 deletions
diff --git a/src/common/fs/fs_util.cpp b/src/common/fs/fs_util.cpp
index e77958224..813a713c3 100644
--- a/src/common/fs/fs_util.cpp
+++ b/src/common/fs/fs_util.cpp
@@ -36,63 +36,4 @@ std::string PathToUTF8String(const std::filesystem::path& path) {
36 return ToUTF8String(path.u8string()); 36 return ToUTF8String(path.u8string());
37} 37}
38 38
39std::u8string U8FilenameSanitizer(const std::u8string_view u8filename) {
40 std::u8string u8path_sanitized{u8filename.begin(), u8filename.end()};
41 size_t eSizeSanitized = u8path_sanitized.size();
42
43 // The name is improved to make it look more beautiful and prohibited characters and shapes are
44 // removed. Switch is used since it is better with many conditions.
45 for (size_t i = 0; i < eSizeSanitized; i++) {
46 switch (u8path_sanitized[i]) {
47 case u8':':
48 if (i == 0 || i == eSizeSanitized - 1) {
49 u8path_sanitized.replace(i, 1, u8"_");
50 } else if (u8path_sanitized[i - 1] == u8' ') {
51 u8path_sanitized.replace(i, 1, u8"-");
52 } else {
53 u8path_sanitized.replace(i, 1, u8" -");
54 eSizeSanitized++;
55 }
56 break;
57 case u8'\\':
58 case u8'/':
59 case u8'*':
60 case u8'?':
61 case u8'\"':
62 case u8'<':
63 case u8'>':
64 case u8'|':
65 case u8'\0':
66 u8path_sanitized.replace(i, 1, u8"_");
67 break;
68 default:
69 break;
70 }
71 }
72
73 // Delete duplicated spaces and dots
74 for (size_t i = 0; i < eSizeSanitized - 1; i++) {
75 if ((u8path_sanitized[i] == u8' ' && u8path_sanitized[i + 1] == u8' ') ||
76 (u8path_sanitized[i] == u8'.' && u8path_sanitized[i + 1] == u8'.')) {
77 u8path_sanitized.erase(i, 1);
78 i--;
79 }
80 }
81
82 // Delete all spaces and dots at the end of the name
83 while (u8path_sanitized.back() == u8' ' || u8path_sanitized.back() == u8'.') {
84 u8path_sanitized.pop_back();
85 }
86
87 if (u8path_sanitized.empty()) {
88 return u8"";
89 }
90
91 return u8path_sanitized;
92}
93
94std::string UTF8FilenameSanitizer(const std::string_view filename) {
95 return ToUTF8String(U8FilenameSanitizer(ToU8String(filename)));
96}
97
98} // namespace Common::FS 39} // namespace Common::FS