mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-05-29 17:18:00 -04:00
Sanitize profile filenames
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include "StringUtils.h"
|
||||
|
||||
@@ -94,3 +95,31 @@ const std::string StringUtils::remove_null_terminating_chars(std::string input)
|
||||
|
||||
return(input);
|
||||
}
|
||||
|
||||
std::string StringUtils::make_filename(std::string input)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Replace : characters with - characters |
|
||||
\*-----------------------------------------------------*/
|
||||
input = std::regex_replace(input, std::regex(":"), "-");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove all other characters |
|
||||
\*-----------------------------------------------------*/
|
||||
input = std::regex_replace(input, std::regex("[#%&\\{\\}\\\\<>\\*\\?/!`';@+|=]"), "");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove leading . characters |
|
||||
\*-----------------------------------------------------*/
|
||||
input = std::regex_replace(input, std::regex("^\\.+"), "");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove control characters |
|
||||
\*-----------------------------------------------------*/
|
||||
input = std::regex_replace(input, std::regex("[\\x00-\\x1F\\x7F]"), "");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Return complete string |
|
||||
\*-----------------------------------------------------*/
|
||||
return(input);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user