From: Rolf Eike Beer Date: Wed, 23 Oct 2024 06:39:15 +0000 (+0200) Subject: kconfig: qconf: simplify character replacement X-Git-Tag: v6.13-rc1~16^2~67 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=8b36d3f2e612866e705b16e9c792e10b62c6c10e;p=linux-2.6-block.git 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 Signed-off-by: Masahiro Yamada --- 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 patterns; + patterns['<'] = "<"; + patterns['>'] = ">"; + patterns['&'] = "&"; + patterns['"'] = """; + patterns['\n'] = "
"; + 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, "
"); - i += 4; - break; + const QString n = patterns.value(res[i], QString()); + if (!n.isEmpty()) { + res.replace(i, 1, n); + i += n.length(); } } return res;