| 72 | } |
| 73 | |
| 74 | void Version::parse() |
| 75 | { |
| 76 | m_sections.clear(); |
| 77 | QString currentSection; |
| 78 | |
| 79 | if (m_string.isEmpty()) |
| 80 | return; |
| 81 | |
| 82 | auto classChange = [&](QChar lastChar, QChar currentChar) { |
| 83 | if (lastChar.isNull()) |
| 84 | return false; |
| 85 | if (lastChar.isDigit() != currentChar.isDigit()) |
| 86 | return true; |
| 87 | |
| 88 | const QList<QChar> s_separators{ '.', '-', '+' }; |
| 89 | if (s_separators.contains(currentChar) && currentSection.at(0) != currentChar) |
| 90 | return true; |
| 91 | |
| 92 | return false; |
| 93 | }; |
| 94 | |
| 95 | currentSection += m_string.at(0); |
| 96 | for (int i = 1; i < m_string.size(); ++i) { |
| 97 | const auto& current_char = m_string.at(i); |
| 98 | if (classChange(m_string.at(i - 1), current_char)) { |
| 99 | if (!currentSection.isEmpty()) |
| 100 | m_sections.append(Section(currentSection)); |
| 101 | currentSection = ""; |
| 102 | } |
| 103 | |
| 104 | currentSection += current_char; |
| 105 | } |
| 106 | |
| 107 | if (!currentSection.isEmpty()) |
| 108 | m_sections.append(Section(currentSection)); |
| 109 | } |
| 110 | |
| 111 | /// qDebug print support for the Version class |
| 112 | QDebug operator<<(QDebug debug, const Version& v) |