summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Eike Beer <eb@emlix.com>2024-10-23 08:39:15 +0200
committerMasahiro Yamada <masahiroy@kernel.org>2024-11-06 08:46:34 +0900
commit8b36d3f2e612866e705b16e9c792e10b62c6c10e (patch)
treead409687fc98f7cc27b59003a0d77156ed2b82fb
parent5a4bed0fad83cdecc91dfd541b326801d3979564 (diff)
downloadlwn-8b36d3f2e612866e705b16e9c792e10b62c6c10e.tar.gz
lwn-8b36d3f2e612866e705b16e9c792e10b62c6c10e.zip
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>
-rw-r--r--scripts/kconfig/qconf.cc33
1 files changed, 12 insertions, 21 deletions
diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
index f01fa1481d6e..90f139480eda 100644
--- a/scripts/kconfig/qconf.cc
+++ b/scripts/kconfig/qconf.cc
@@ -1122,28 +1122,19 @@ QString ConfigInfoView::print_filter(const QString &str)
{
QRegularExpression re("[<>&\"\\n]");
QString res = str;
+
+ QHash<QChar, QString> patterns;
+ patterns['<'] = "&lt;";
+ patterns['>'] = "&gt;";
+ patterns['&'] = "&amp;";
+ patterns['"'] = "&quot;";
+ patterns['\n'] = "<br>";
+
for (int i = 0; (i = res.indexOf(re, i)) >= 0;) {
- switch (res[i].toLatin1()) {
- case '<':
- res.replace(i, 1, "&lt;");
- i += 4;
- break;
- case '>':
- res.replace(i, 1, "&gt;");
- i += 4;
- break;
- case '&':
- res.replace(i, 1, "&amp;");
- i += 5;
- break;
- case '"':
- res.replace(i, 1, "&quot;");
- 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;