diff options
Diffstat (limited to '')
-rw-r--r-- | src/common/fs/fs_util.cpp | 44 | ||||
-rw-r--r-- | src/common/fs/fs_util.h | 8 | ||||
-rw-r--r-- | src/common/fs/path_util.cpp | 8 |
3 files changed, 29 insertions, 31 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) { return ToUTF8String(path.u8string()); } -std::u8string U8FilenameSantizer(const std::u8string_view u8filename) { - std::u8string u8path_santized{u8filename.begin(), u8filename.end()}; - size_t eSizeSanitized = u8path_santized.size(); +std::u8string U8FilenameSanitizer(const std::u8string_view u8filename) { + std::u8string u8path_sanitized{u8filename.begin(), u8filename.end()}; + size_t eSizeSanitized = u8path_sanitized.size(); - // Special case for ":", for example: 'Pepe: La secuela' --> 'Pepe - La - // secuela' or 'Pepe : La secuela' --> 'Pepe - La secuela' + // The name is improved to make it look more beautiful and prohibited characters and shapes are + // removed. Switch is used since it is better with many conditions. for (size_t i = 0; i < eSizeSanitized; i++) { - switch (u8path_santized[i]) { + switch (u8path_sanitized[i]) { case u8':': if (i == 0 || i == eSizeSanitized - 1) { - u8path_santized.replace(i, 1, u8"_"); - } else if (u8path_santized[i - 1] == u8' ') { - u8path_santized.replace(i, 1, u8"-"); + u8path_sanitized.replace(i, 1, u8"_"); + } else if (u8path_sanitized[i - 1] == u8' ') { + u8path_sanitized.replace(i, 1, u8"-"); } else { - u8path_santized.replace(i, 1, u8" -"); + u8path_sanitized.replace(i, 1, u8" -"); eSizeSanitized++; } break; @@ -63,36 +63,36 @@ std::u8string U8FilenameSantizer(const std::u8string_view u8filename) { case u8'>': case u8'|': case u8'\0': - u8path_santized.replace(i, 1, u8"_"); + u8path_sanitized.replace(i, 1, u8"_"); break; default: break; } } - // Delete duplicated spaces || Delete duplicated dots (MacOS i think) + // Delete duplicated spaces and dots for (size_t i = 0; i < eSizeSanitized - 1; i++) { - if ((u8path_santized[i] == u8' ' && u8path_santized[i + 1] == u8' ') || - (u8path_santized[i] == u8'.' && u8path_santized[i + 1] == u8'.')) { - u8path_santized.erase(i, 1); + if ((u8path_sanitized[i] == u8' ' && u8path_sanitized[i + 1] == u8' ') || + (u8path_sanitized[i] == u8'.' && u8path_sanitized[i + 1] == u8'.')) { + u8path_sanitized.erase(i, 1); i--; } } - // Delete all spaces and dots at the end (Windows almost) - while (u8path_santized.back() == u8' ' || u8path_santized.back() == u8'.') { - u8path_santized.pop_back(); + // Delete all spaces and dots at the end of the name + while (u8path_sanitized.back() == u8' ' || u8path_sanitized.back() == u8'.') { + u8path_sanitized.pop_back(); } - if (u8path_santized.empty()) { + if (u8path_sanitized.empty()) { return u8""; } - return u8path_santized; + return u8path_sanitized; } -std::string UTF8FilenameSantizer(const std::string_view filename) { - return ToUTF8String(U8FilenameSantizer(ToU8String(filename))); +std::string UTF8FilenameSanitizer(const std::string_view filename) { + return ToUTF8String(U8FilenameSanitizer(ToU8String(filename))); } } // namespace Common::FS diff --git a/src/common/fs/fs_util.h b/src/common/fs/fs_util.h index dbb4f5a9a..daec1f8cb 100644 --- a/src/common/fs/fs_util.h +++ b/src/common/fs/fs_util.h @@ -87,19 +87,19 @@ concept IsChar = std::same_as<T, char>; * * @param u8_string dirty encoded filename string * - * @returns utf8_string santized filename string + * @returns utf8_string sanitized filename string * */ -[[nodiscard]] std::u8string U8FilenameSantizer(const std::u8string_view u8filename); +[[nodiscard]] std::u8string U8FilenameSanitizer(const std::u8string_view u8filename); /** * Fix filename (remove invalid characters) * * @param utf8_string dirty encoded filename string * - * @returns utf8_string santized filename string + * @returns utf8_string sanitized filename string * */ -[[nodiscard]] std::string UTF8FilenameSantizer(const std::string_view filename); +[[nodiscard]] std::string UTF8FilenameSanitizer(const std::string_view filename); } // namespace Common::FS
\ No newline at end of file diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp index bccf953e4..3d88fcf4f 100644 --- a/src/common/fs/path_util.cpp +++ b/src/common/fs/path_util.cpp @@ -260,9 +260,8 @@ fs::path GetExeDirectory() { // the Windows library (Filesystem converts the strings literally). return fs::path{Common::UTF16ToUTF8(wideExePath)}.parent_path(); } else { - LOG_ERROR(Common_Filesystem, - "[GetExeDirectory] Failed to get the path to the executable of the current " - "process"); + LOG_ERROR(Common_Filesystem, "Failed to get the path to the executable of the current " + "process"); } return fs::path{}; @@ -279,8 +278,7 @@ fs::path GetAppDataRoamingDirectory() { // the Windows library (Filesystem converts the strings literally). return fs::path{Common::UTF16ToUTF8(wideAppdataRoamingPath)}; } else { - LOG_ERROR(Common_Filesystem, - "[GetAppDataRoamingDirectory] Failed to get the path to the %APPDATA% directory"); + LOG_ERROR(Common_Filesystem, "Failed to get the path to the %APPDATA% directory"); } return fs::path{}; |