[PATCH 7/7] kconfig: qconf: simplify character replacement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 scripts/kconfig/qconf.cc | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
index 4b2f707c9203..f07a463c5760 100644
--- a/scripts/kconfig/qconf.cc
+++ b/scripts/kconfig/qconf.cc
@@ -1123,28 +1123,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;
-- 
2.47.0


-- 
Rolf Eike Beer

emlix GmbH
Headquarters: Berliner Str. 12, 37073 Göttingen, Germany
Phone +49 (0)551 30664-0, e-mail info@xxxxxxxxx
District Court of Göttingen, Registry Number HR B 3160
Managing Directors: Heike Jordan, Dr. Uwe Kracke
VAT ID No. DE 205 198 055
Office Berlin: Panoramastr. 1, 10178 Berlin, Germany
Office Bonn: Bachstr. 6, 53115 Bonn, Germany
http://www.emlix.com

emlix - your embedded Linux partner







[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux