mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2024-12-29 17:23:36 +00:00
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 <eb@emlix.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
This commit is contained in:
parent
5a4bed0fad
commit
8b36d3f2e6
@ -1122,28 +1122,19 @@ QString ConfigInfoView::print_filter(const QString &str)
|
||||
{
|
||||
QRegularExpression re("[<>&\"\\n]");
|
||||
QString res = str;
|
||||
|
||||
QHash<QChar, QString> patterns;
|
||||
patterns['<'] = "<";
|
||||
patterns['>'] = ">";
|
||||
patterns['&'] = "&";
|
||||
patterns['"'] = """;
|
||||
patterns['\n'] = "<br>";
|
||||
|
||||
for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
|
||||
switch (res[i].toLatin1()) {
|
||||
case '<':
|
||||
res.replace(i, 1, "<");
|
||||
i += 4;
|
||||
break;
|
||||
case '>':
|
||||
res.replace(i, 1, ">");
|
||||
i += 4;
|
||||
break;
|
||||
case '&':
|
||||
res.replace(i, 1, "&");
|
||||
i += 5;
|
||||
break;
|
||||
case '"':
|
||||
res.replace(i, 1, """);
|
||||
i += 6;
|
||||
break;
|
||||
case '\n':
|
||||
res.replace(i, 1, "<br>");
|
||||
i += 4;
|
||||
break;
|
||||
const QString n = patterns.value(res[i], QString());
|
||||
if (!n.isEmpty()) {
|
||||
res.replace(i, 1, n);
|
||||
i += n.length();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
Loading…
Reference in New Issue
Block a user