Version.cpp: Use anonymous function to eliminate code duplication

Signed-off-by: Edgars Cīrulis <edgarsscirulis@gmail.com>
This commit is contained in:
Edgars Cīrulis 2023-01-15 14:30:18 +02:00
parent 6fb837c529
commit de11017552
No known key found for this signature in database
GPG Key ID: 307C4E4663F1FCC3

View File

@ -75,26 +75,18 @@ void Version::parse()
{
m_sections.clear();
QString currentSection;
bool lastCharWasDigit = false;
auto classChange = [] (QChar lastChar, QChar currentChar) {
return (( lastChar.isLetter() && currentChar.isDigit() ) || (lastChar.isDigit() && currentChar.isLetter()) );
};
for (int i = 0; i < m_string.size(); ++i) {
if(m_string[i].isDigit()){
if(!lastCharWasDigit){
if(m_string[i].isDigit() || m_string[i].isLetter()){
if(i>0 && classChange(m_string[i-1], m_string[i])){
if(!currentSection.isEmpty()){
m_sections.append(Section(currentSection));
}
currentSection = "";
}
currentSection += m_string[i];
lastCharWasDigit = true;
}else if(m_string[i].isLetter()){
if(lastCharWasDigit){
if(!currentSection.isEmpty()){
m_sections.append(Section(currentSection));
}
currentSection = "";
}
currentSection += m_string[i];
lastCharWasDigit = false;
}
else if(m_string[i] == '.' || m_string[i] == '-' || m_string[i] == '_'){
if(!currentSection.isEmpty()){