Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Rolf Eike Beer and committed by
Masahiro Yamada
8b36d3f2 5a4bed0f

+12 -21
+12 -21
scripts/kconfig/qconf.cc
··· 1122 1122 { 1123 1123 QRegularExpression re("[<>&\"\\n]"); 1124 1124 QString res = str; 1125 + 1126 + QHash<QChar, QString> patterns; 1127 + patterns['<'] = "&lt;"; 1128 + patterns['>'] = "&gt;"; 1129 + patterns['&'] = "&amp;"; 1130 + patterns['"'] = "&quot;"; 1131 + patterns['\n'] = "<br>"; 1132 + 1125 1133 for (int i = 0; (i = res.indexOf(re, i)) >= 0;) { 1126 - switch (res[i].toLatin1()) { 1127 - case '<': 1128 - res.replace(i, 1, "&lt;"); 1129 - i += 4; 1130 - break; 1131 - case '>': 1132 - res.replace(i, 1, "&gt;"); 1133 - i += 4; 1134 - break; 1135 - case '&': 1136 - res.replace(i, 1, "&amp;"); 1137 - i += 5; 1138 - break; 1139 - case '"': 1140 - res.replace(i, 1, "&quot;"); 1141 - i += 6; 1142 - break; 1143 - case '\n': 1144 - res.replace(i, 1, "<br>"); 1145 - i += 4; 1146 - break; 1134 + const QString n = patterns.value(res[i], QString()); 1135 + if (!n.isEmpty()) { 1136 + res.replace(i, 1, n); 1137 + i += n.length(); 1147 1138 } 1148 1139 } 1149 1140 return res;