Names are now cleaned for illegal symbols in filenames
This commit is contained in:
parent
f68041aa44
commit
02b282b80f
28
common.cpp
28
common.cpp
@ -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;
|
||||
}
|
||||
|
||||
1
common.h
1
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_
|
||||
|
||||
Loading…
Reference in New Issue
Block a user