Base: Replace if else with switch statement

This commit is contained in:
Ladislav Michl
2024-01-20 18:18:09 +01:00
committed by 3x380V
parent 95b37fa806
commit f1fdd2e2a9
5 changed files with 115 additions and 121 deletions

View File

@@ -76,32 +76,34 @@ std::string Persistence::encodeAttribute(const std::string& str)
{
std::string tmp;
for (char it : str) {
if (it == '<') {
tmp += "&lt;";
}
else if (it == '\"') {
tmp += "&quot;";
}
else if (it == '\'') {
tmp += "&apos;";
}
else if (it == '&') {
tmp += "&amp;";
}
else if (it == '>') {
tmp += "&gt;";
}
else if (it == '\r') {
tmp += "&#13;";
}
else if (it == '\n') {
tmp += "&#10;";
}
else if (it == '\t') {
tmp += "&#9;";
}
else {
tmp += it;
switch (it) {
case '<':
tmp += "&lt;";
break;
case '\"':
tmp += "&quot;";
break;
case '\'':
tmp += "&apos;";
break;
case '&':
tmp += "&amp;";
break;
case '>':
tmp += "&gt;";
break;
case '\r':
tmp += "&#13;";
break;
case '\n':
tmp += "&#10;";
break;
case '\t':
tmp += "&#9;";
break;
default:
tmp += it;
break;
}
}