mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-09-17 15:55:46 -04:00
Sanitize profile filenames
This commit is contained in:
1 parent
69a8c84b4d
commit
156b7d0f89
4 files changed
+35
-6
No files matched your search
@@ -22,6 +22,7 @@
|
||||
#include <cctype>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include "StringUtils.h"
|
||||
|
||||
@@ -113,6 +114,34 @@ std::string StringUtils::u32int_to_hexString(unsigned int value)
|
||||
return std::string(hex_str);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
std::string StringUtils::normalize_hex_id(const std::string& id)
|
||||
{
|
||||
std::string out;
|
||||
|
||||
Reference in new issue
Block a user