FileSystem: Add SanitizeFilename() overload for std::string
This commit is contained in:
parent
d97a107b62
commit
322f1492b2
2 changed files with 12 additions and 1 deletions
|
|
@ -169,7 +169,7 @@ void CanonicalizePath(std::string& path, bool OSPath /*= true*/)
|
|||
static inline bool FileSystemCharacterIsSane(char c, bool StripSlashes)
|
||||
{
|
||||
if (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c >= '0' && c <= '9') && c != ' ' && c != ' ' &&
|
||||
c != '_' && c != '-')
|
||||
c != '_' && c != '-' && c != '.')
|
||||
{
|
||||
if (!StripSlashes && (c == '/' || c == '\\'))
|
||||
return true;
|
||||
|
|
@ -239,6 +239,16 @@ void SanitizeFileName(String& Destination, bool StripSlashes /* = true */)
|
|||
return SanitizeFileName(Destination, Destination, StripSlashes);
|
||||
}
|
||||
|
||||
void SanitizeFileName(std::string& Destination, bool StripSlashes /* = true*/)
|
||||
{
|
||||
const std::size_t len = Destination.length();
|
||||
for (std::size_t i = 0; i < len; i++)
|
||||
{
|
||||
if (!FileSystemCharacterIsSane(Destination[i], StripSlashes))
|
||||
Destination[i] = '_';
|
||||
}
|
||||
}
|
||||
|
||||
bool IsAbsolutePath(const std::string_view& path)
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue