Version.cpp: Decompose version strings according to flexver

Co-authored-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Signed-off-by: Edgars Cīrulis <edgarsscirulis@gmail.com>
This commit is contained in:
Edgars Cīrulis 2023-01-17 06:53:01 +02:00
parent a84e4b0e07
commit 3bec4a80b3
No known key found for this signature in database
GPG Key ID: 307C4E4663F1FCC3

View File

@ -75,25 +75,20 @@ void Version::parse()
{ {
m_sections.clear(); m_sections.clear();
QString currentSection; QString currentSection;
auto classChange = [](QChar lastChar, QChar currentChar) { 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) { for (int i = 0; i < m_string.size(); ++i) {
const auto& current_char = m_string.at(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)) || current_char == '.' || current_char == '-' || current_char == '+') {
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 (!currentSection.isEmpty()) { if (!currentSection.isEmpty()) {
m_sections.append(Section(currentSection)); m_sections.append(Section(currentSection));
} }
currentSection = ""; currentSection = "";
} }
currentSection += current_char;
} }
if (!currentSection.isEmpty()) { if (!currentSection.isEmpty()) {
m_sections.append(Section(currentSection)); m_sections.append(Section(currentSection));