From 27aca8101f100ea06f8ef15a513063c05a41ee62 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 1 Feb 2023 16:10:22 +0100 Subject: [PATCH] QPlatformTheme::removeMnemonics(): use QStringView internally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- src/gui/kernel/qplatformtheme.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 1da438d55a..6b6eb896ed 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -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;