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.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/common/fs/fs_util.cpp b/src/common/fs/fs_util.cpp
index 442f63728..e77958224 100644
--- a/src/common/fs/fs_util.cpp
+++ b/src/common/fs/fs_util.cpp
@@ -36,21 +36,21 @@ std::string PathToUTF8String(const std::filesystem::path& path) {
36 return ToUTF8String(path.u8string()); 36 return ToUTF8String(path.u8string());
37} 37}
38 38
39std::u8string U8FilenameSantizer(const std::u8string_view u8filename) { 39std::u8string U8FilenameSanitizer(const std::u8string_view u8filename) {
40 std::u8string u8path_santized{u8filename.begin(), u8filename.end()}; 40 std::u8string u8path_sanitized{u8filename.begin(), u8filename.end()};
41 size_t eSizeSanitized = u8path_santized.size(); 41 size_t eSizeSanitized = u8path_sanitized.size();
42 42
43 // Special case for ":", for example: 'Pepe: La secuela' --> 'Pepe - La 43 // The name is improved to make it look more beautiful and prohibited characters and shapes are
44 // secuela' or 'Pepe : La secuela' --> 'Pepe - La secuela' 44 // removed. Switch is used since it is better with many conditions.
45 for (size_t i = 0; i < eSizeSanitized; i++) { 45 for (size_t i = 0; i < eSizeSanitized; i++) {
46 switch (u8path_santized[i]) { 46 switch (u8path_sanitized[i]) {
47 case u8':': 47 case u8':':
48 if (i == 0 || i == eSizeSanitized - 1) { 48 if (i == 0 || i == eSizeSanitized - 1) {
49 u8path_santized.replace(i, 1, u8"_"); 49 u8path_sanitized.replace(i, 1, u8"_");
50 } else if (u8path_santized[i - 1] == u8' ') { 50 } else if (u8path_sanitized[i - 1] == u8' ') {
51 u8path_santized.replace(i, 1, u8"-"); 51 u8path_sanitized.replace(i, 1, u8"-");
52 } else { 52 } else {
53 u8path_santized.replace(i, 1, u8" -"); 53 u8path_sanitized.replace(i, 1, u8" -");
54 eSizeSanitized++; 54 eSizeSanitized++;
55 } 55 }
56 break; 56 break;
@@ -63,36 +63,36 @@ std::u8string U8FilenameSantizer(const std::u8string_view u8filename) {
63 case u8'>': 63 case u8'>':
64 case u8'|': 64 case u8'|':
65 case u8'\0': 65 case u8'\0':
66 u8path_santized.replace(i, 1, u8"_"); 66 u8path_sanitized.replace(i, 1, u8"_");
67 break; 67 break;
68 default: 68 default:
69 break; 69 break;
70 } 70 }
71 } 71 }
72 72
73 // Delete duplicated spaces || Delete duplicated dots (MacOS i think) 73 // Delete duplicated spaces and dots
74 for (size_t i = 0; i < eSizeSanitized - 1; i++) { 74 for (size_t i = 0; i < eSizeSanitized - 1; i++) {
75 if ((u8path_santized[i] == u8' ' && u8path_santized[i + 1] == u8' ') || 75 if ((u8path_sanitized[i] == u8' ' && u8path_sanitized[i + 1] == u8' ') ||
76 (u8path_santized[i] == u8'.' && u8path_santized[i + 1] == u8'.')) { 76 (u8path_sanitized[i] == u8'.' && u8path_sanitized[i + 1] == u8'.')) {
77 u8path_santized.erase(i, 1); 77 u8path_sanitized.erase(i, 1);
78 i--; 78 i--;
79 } 79 }
80 } 80 }
81 81
82 // Delete all spaces and dots at the end (Windows almost) 82 // Delete all spaces and dots at the end of the name
83 while (u8path_santized.back() == u8' ' || u8path_santized.back() == u8'.') { 83 while (u8path_sanitized.back() == u8' ' || u8path_sanitized.back() == u8'.') {
84 u8path_santized.pop_back(); 84 u8path_sanitized.pop_back();
85 } 85 }
86 86
87 if (u8path_santized.empty()) { 87 if (u8path_sanitized.empty()) {
88 return u8""; 88 return u8"";
89 } 89 }
90 90
91 return u8path_santized; 91 return u8path_sanitized;
92} 92}
93 93
94std::string UTF8FilenameSantizer(const std::string_view filename) { 94std::string UTF8FilenameSanitizer(const std::string_view filename) {
95 return ToUTF8String(U8FilenameSantizer(ToU8String(filename))); 95 return ToUTF8String(U8FilenameSanitizer(ToU8String(filename)));
96} 96}
97 97
98} // namespace Common::FS 98} // namespace Common::FS