add function to escape special characters in file names

This commit is contained in:
wmayer
2019-09-28 19:32:34 +02:00
parent fb7a03a04d
commit 426674f225
2 changed files with 35 additions and 0 deletions

View File

@@ -192,6 +192,38 @@ std::string Base::Tools::escapedUnicodeToUtf8(const std::string& s)
return string;
}
QString Base::Tools::escapeEncodeFilename(const QString& s)
{
QString result;
const int len = s.length();
result.reserve(int(len * 1.1));
for (int i = 0; i < len; ++i) {
if (s.at(i) == QLatin1Char('\"'))
result += QLatin1String("\\\"");
else if (s.at(i) == QLatin1Char('\''))
result += QLatin1String("\\\'");
else
result += s.at(i);
}
result.squeeze();
return result;
}
std::string Base::Tools::escapeEncodeFilename(const std::string& s)
{
std::string result;
size_t len = s.size();
for (size_t i = 0; i < len; ++i) {
if (s.at(i) == '\"')
result += "\\\"";
else if (s.at(i) == '\'')
result += "\\\'";
else
result += s.at(i);
}
return result;
}
// ----------------------------------------------------------------------------
using namespace Base;