Skip to content

Commit 8b36d3f

Browse files
DerDakonmasahir0y
authored andcommitted
kconfig: qconf: simplify character replacement
Replace the hand crafted lookup table with a QHash. This has the nice benefit that the added offsets can not get out of sync with the length of the replacement strings. Signed-off-by: Rolf Eike Beer <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 5a4bed0 commit 8b36d3f

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

scripts/kconfig/qconf.cc

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,28 +1122,19 @@ QString ConfigInfoView::print_filter(const QString &str)
11221122
{
11231123
QRegularExpression re("[<>&\"\\n]");
11241124
QString res = str;
1125+
1126+
QHash<QChar, QString> patterns;
1127+
patterns['<'] = "&lt;";
1128+
patterns['>'] = "&gt;";
1129+
patterns['&'] = "&amp;";
1130+
patterns['"'] = "&quot;";
1131+
patterns['\n'] = "<br>";
1132+
11251133
for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
1126-
switch (res[i].toLatin1()) {
1127-
case '<':
1128-
res.replace(i, 1, "&lt;");
1129-
i += 4;
1130-
break;
1131-
case '>':
1132-
res.replace(i, 1, "&gt;");
1133-
i += 4;
1134-
break;
1135-
case '&':
1136-
res.replace(i, 1, "&amp;");
1137-
i += 5;
1138-
break;
1139-
case '"':
1140-
res.replace(i, 1, "&quot;");
1141-
i += 6;
1142-
break;
1143-
case '\n':
1144-
res.replace(i, 1, "<br>");
1145-
i += 4;
1146-
break;
1134+
const QString n = patterns.value(res[i], QString());
1135+
if (!n.isEmpty()) {
1136+
res.replace(i, 1, n);
1137+
i += n.length();
11471138
}
11481139
}
11491140
return res;

0 commit comments

Comments
 (0)