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'); QString returnText(original.size(), u'\0');
int finalDest = 0; int finalDest = 0;
int currPos = 0; QStringView text(original);
int l = original.size(); while (!text.isEmpty()) {
while (l) { if (text.startsWith(u'&')) {
if (original.at(currPos) == u'&') { text = text.sliced(1);
++currPos; if (text.isEmpty())
--l;
if (l == 0)
break; 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: // Advance over the matched mnemonic:
currPos += 4; text = text.sliced(4);
l -= 4;
// Also strip any leading space before it: // Also strip any leading space before it:
while (finalDest > 0 && returnText.at(finalDest - 1).isSpace()) while (finalDest > 0 && returnText.at(finalDest - 1).isSpace())
--finalDest; --finalDest;
continue; continue;
} }
returnText[finalDest] = original.at(currPos); returnText[finalDest] = text.front();
++currPos; text = text.sliced(1);
++finalDest; ++finalDest;
--l;
} }
returnText.truncate(finalDest); returnText.truncate(finalDest);
return returnText; return returnText;