Names are now cleaned for illegal symbols in filenames

This commit is contained in:
Nedko 2024-07-01 14:46:18 +03:00
parent f68041aa44
commit 02b282b80f
2 changed files with 29 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#include "common.h"
#include <fstream>
#include <set>
#include <sys/stat.h>
@ -159,3 +160,30 @@ string trim_whitespace(const string& s)
return result;
}
string clean_filename(const string& s)
{
string result = s;
set<char> 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;
}

View File

@ -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_