From 02b282b80fc6f19d72216d17b9a04bc27aae057c Mon Sep 17 00:00:00 2001 From: Nedko Date: Mon, 1 Jul 2024 14:46:18 +0300 Subject: [PATCH] Names are now cleaned for illegal symbols in filenames --- common.cpp | 28 ++++++++++++++++++++++++++++ common.h | 1 + 2 files changed, 29 insertions(+) diff --git a/common.cpp b/common.cpp index cb4a3da..8dae5b7 100644 --- a/common.cpp +++ b/common.cpp @@ -1,6 +1,7 @@ #include "common.h" #include +#include #include @@ -159,3 +160,30 @@ string trim_whitespace(const string& s) return result; } + +string clean_filename(const string& s) +{ + string result = s; + + set illegal; + + illegal.insert('/'); + illegal.insert('\\'); + illegal.insert('<'); + illegal.insert('>'); + illegal.insert(':'); + illegal.insert('"'); + illegal.insert('|'); + illegal.insert('?'); + illegal.insert('*'); + + for (char& c : result) + { + if (0 != illegal.count(c)) + { + c = ';'; + } + } + + return result; +} diff --git a/common.h b/common.h index 12c21db..c069907 100644 --- a/common.h +++ b/common.h @@ -18,5 +18,6 @@ void json_extract(const nlohmann::json& j, const std::string& key, void json_extract(const nlohmann::json& j, const std::string& key, bool& out); bool ensure_folder(const std::string& main_path, const std::string& folder); std::string trim_whitespace(const std::string& s); +std::string clean_filename(const std::string& s); #endif // COMMON_H_