QPlatformTheme::removeMnemonics(): use QStringView internally

One QStringView variable can replace a current position and remaining
length variable, while making the code a little easier to read.

Change-Id: Ie491cff08f624c7fba3accae87a3a03a883262a9
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Edward Welbourne 2023-02-01 16:10:22 +01:00
parent 6971bfab44
commit 27aca8101f

View File

@ -825,27 +825,23 @@ QString QPlatformTheme::removeMnemonics(const QString &original)
};
QString returnText(original.size(), u'\0');
int finalDest = 0;
int currPos = 0;
int l = original.size();
while (l) {
if (original.at(currPos) == u'&') {
++currPos;
--l;
if (l == 0)
QStringView text(original);
while (!text.isEmpty()) {
if (text.startsWith(u'&')) {
text = text.sliced(1);
if (text.isEmpty())
break;
} else if (l >= 4 && mnemonicInParentheses(QStringView{original}.sliced(currPos, 4))) {
} else if (text.size() >= 4 && mnemonicInParentheses(text.first(4))) {
// Advance over the matched mnemonic:
currPos += 4;
l -= 4;
text = text.sliced(4);
// Also strip any leading space before it:
while (finalDest > 0 && returnText.at(finalDest - 1).isSpace())
--finalDest;
continue;
}
returnText[finalDest] = original.at(currPos);
++currPos;
returnText[finalDest] = text.front();
text = text.sliced(1);
++finalDest;
--l;
}
returnText.truncate(finalDest);
return returnText;