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_