From 3bec4a80b3de58d31992eda8497a3d099190b92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgars=20C=C4=ABrulis?= Date: Tue, 17 Jan 2023 06:53:01 +0200 Subject: [PATCH] Version.cpp: Decompose version strings according to flexver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rachel Powers <508861+Ryex@users.noreply.github.com> Signed-off-by: Edgars Cīrulis --- launcher/Version.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/launcher/Version.cpp b/launcher/Version.cpp index 0640e6d3..01f513e3 100644 --- a/launcher/Version.cpp +++ b/launcher/Version.cpp @@ -75,25 +75,20 @@ void Version::parse() { m_sections.clear(); QString currentSection; + auto classChange = [](QChar lastChar, QChar currentChar) { - return ((lastChar.isLetter() && currentChar.isDigit()) || (lastChar.isDigit() && currentChar.isLetter())); + return !lastChar.isNull() && ((!lastChar.isDigit() && currentChar.isDigit()) || (lastChar.isDigit() && !currentChar.isDigit())); }; + for (int i = 0; i < m_string.size(); ++i) { const auto& current_char = m_string.at(i); - if (current_char.isDigit() || current_char.isLetter()) { - if (i > 0 && classChange(m_string.at(i - 1), current_char)) { - if (!currentSection.isEmpty()) { - m_sections.append(Section(currentSection)); - } - currentSection = ""; - } - currentSection += current_char; - } else if (current_char == '.' || current_char == '-' || current_char == '_') { + if ((i > 0 && classChange(m_string.at(i - 1), current_char)) || current_char == '.' || current_char == '-' || current_char == '+') { if (!currentSection.isEmpty()) { m_sections.append(Section(currentSection)); } currentSection = ""; } + currentSection += current_char; } if (!currentSection.isEmpty()) { m_sections.append(Section(currentSection));