Version.cpp: Use anonymous function to eliminate code duplication
Signed-off-by: Edgars Cīrulis <edgarsscirulis@gmail.com>
This commit is contained in:
parent
6fb837c529
commit
de11017552
@ -75,26 +75,18 @@ void Version::parse()
|
|||||||
{
|
{
|
||||||
m_sections.clear();
|
m_sections.clear();
|
||||||
QString currentSection;
|
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) {
|
for (int i = 0; i < m_string.size(); ++i) {
|
||||||
if(m_string[i].isDigit()){
|
if(m_string[i].isDigit() || m_string[i].isLetter()){
|
||||||
if(!lastCharWasDigit){
|
if(i>0 && classChange(m_string[i-1], m_string[i])){
|
||||||
if(!currentSection.isEmpty()){
|
if(!currentSection.isEmpty()){
|
||||||
m_sections.append(Section(currentSection));
|
m_sections.append(Section(currentSection));
|
||||||
}
|
}
|
||||||
currentSection = "";
|
currentSection = "";
|
||||||
}
|
}
|
||||||
currentSection += m_string[i];
|
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] == '_'){
|
else if(m_string[i] == '.' || m_string[i] == '-' || m_string[i] == '_'){
|
||||||
if(!currentSection.isEmpty()){
|
if(!currentSection.isEmpty()){
|
||||||
|
Loading…
Reference in New Issue
Block a user