Add Base::Tools::escapeQuotesFromString with corresponding test

To be used to avoid sending unescaped quotes to python console
This commit is contained in:
Adrian Insaurralde Avalos
2024-02-03 09:22:05 -03:00
committed by Chris Hennes
parent 02e5c4986d
commit f5da3925d9
3 changed files with 27 additions and 0 deletions

View File

@@ -236,6 +236,26 @@ std::string Base::Tools::escapedUnicodeToUtf8(const std::string& s)
return string;
}
std::string Base::Tools::escapeQuotesFromString(const std::string& s)
{
std::string result;
size_t len = s.size();
for (size_t i = 0; i < len; ++i) {
switch (s.at(i)) {
case '\"':
result += "\\\"";
break;
case '\'':
result += "\\\'";
break;
default:
result += s.at(i);
break;
}
}
return result;
}
QString Base::Tools::escapeEncodeString(const QString& s)
{
QString result;