]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
kconfig: qconf: simplify character replacement
authorRolf Eike Beer <eb@emlix.com>
Wed, 23 Oct 2024 06:39:15 +0000 (08:39 +0200)
committerMasahiro Yamada <masahiroy@kernel.org>
Tue, 5 Nov 2024 23:46:34 +0000 (08:46 +0900)
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>
scripts/kconfig/qconf.cc

index f01fa1481d6ec60550a40ee861ee599f32ad1b57..90f139480eda4993ca096599e14a20806daef9bf 100644 (file)
@@ -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;