aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorEdgars Cīrulis <edgarsscirulis@gmail.com>2023-01-15 09:47:31 +0200
committerEdgars Cīrulis <edgarsscirulis@gmail.com>2023-01-17 07:13:24 +0200
commitc0c3892064a775b13fd5cae00f58b43bee062003 (patch)
tree2685bdac729d6557291dca623b671858b52d6d61 /launcher
parent72a9b98ef065ffc065dd162124ebbd212fe0d862 (diff)
downloadPrismLauncher-c0c3892064a775b13fd5cae00f58b43bee062003.tar.gz
PrismLauncher-c0c3892064a775b13fd5cae00f58b43bee062003.tar.bz2
PrismLauncher-c0c3892064a775b13fd5cae00f58b43bee062003.zip
Version.cpp: Improve version parsing to handle mixed numeric and alphabetic characters
Signed-off-by: Edgars Cīrulis <edgarsscirulis@gmail.com>
Diffstat (limited to 'launcher')
-rw-r--r--launcher/Version.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/launcher/Version.cpp b/launcher/Version.cpp
index b9090e29..5d814a25 100644
--- a/launcher/Version.cpp
+++ b/launcher/Version.cpp
@@ -74,12 +74,36 @@ bool Version::operator!=(const Version &other) const
void Version::parse()
{
m_sections.clear();
-
- // FIXME: this is bad. versions can contain a lot more separators...
- QStringList parts = m_string.split('.');
-
- for (const auto& part : parts)
- {
- m_sections.append(Section(part));
+ QString currentSection;
+ bool lastCharWasDigit = false;
+ for (int i = 0; i < m_string.size(); ++i) {
+ if(m_string[i].isDigit()){
+ if(!lastCharWasDigit){
+ 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] == '_'){
+ if(!currentSection.isEmpty()){
+ m_sections.append(Section(currentSection));
+ }
+ currentSection = "";
+ }
+ }
+ if (!currentSection.isEmpty()) {
+ m_sections.append(Section(currentSection));
}
}