diff options
author | Petr Mrázek <peterix@gmail.com> | 2016-04-10 04:29:29 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2016-04-30 23:59:23 +0200 |
commit | 47e37635f50c09b4f9a9ee7699e3120bab3e4088 (patch) | |
tree | 061c2f675fb7e244ebe4b54ef206bfbd615c91f8 /logic/java/JavaVersion.cpp | |
parent | fcd4a482f759cd58ee319a51082d0146b7e426e2 (diff) | |
download | MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.tar MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.tar.gz MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.tar.lz MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.tar.xz MultiMC-47e37635f50c09b4f9a9ee7699e3120bab3e4088.zip |
NOISSUE split GUI stuff from logic library
Diffstat (limited to 'logic/java/JavaVersion.cpp')
-rw-r--r-- | logic/java/JavaVersion.cpp | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/logic/java/JavaVersion.cpp b/logic/java/JavaVersion.cpp deleted file mode 100644 index 84fc48a4..00000000 --- a/logic/java/JavaVersion.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "JavaVersion.h" -#include <MMCStrings.h> - -#include <QRegularExpression> -#include <QString> - -JavaVersion & JavaVersion::operator=(const QString & javaVersionString) -{ - string = javaVersionString; - - auto getCapturedInteger = [](const QRegularExpressionMatch & match, const QString &what) -> int - { - auto str = match.captured(what); - if(str.isEmpty()) - { - return 0; - } - return str.toInt(); - }; - - QRegularExpression pattern; - if(javaVersionString.startsWith("1.")) - { - pattern = QRegularExpression ("1[.](?<major>[0-9]+)([.](?<minor>[0-9]+))?(_(?<security>[0-9]+)?)?(-(?<prerelease>[a-zA-Z0-9]+))?"); - } - else - { - pattern = QRegularExpression("(?<major>[0-9]+)([.](?<minor>[0-9]+))?([.](?<security>[0-9]+))?(-(?<prerelease>[a-zA-Z0-9]+))?"); - } - - auto match = pattern.match(string); - parseable = match.hasMatch(); - major = getCapturedInteger(match, "major"); - minor = getCapturedInteger(match, "minor"); - security = getCapturedInteger(match, "security"); - prerelease = match.captured("prerelease"); - return *this; -} - -JavaVersion::JavaVersion(const QString &rhs) -{ - operator=(rhs); -} - -QString JavaVersion::toString() -{ - return string; -} - -bool JavaVersion::requiresPermGen() -{ - if(parseable) - { - return major < 8; - } - return true; -} - -bool JavaVersion::operator<(const JavaVersion &rhs) -{ - if(parseable && rhs.parseable) - { - if(major < rhs.major) - return true; - if(major > rhs.major) - return false; - if(minor < rhs.minor) - return true; - if(minor > rhs.minor) - return false; - if(security < rhs.security) - return true; - if(security > rhs.security) - return false; - - // everything else being equal, consider prerelease status - bool thisPre = !prerelease.isEmpty(); - bool rhsPre = !rhs.prerelease.isEmpty(); - if(thisPre && !rhsPre) - { - // this is a prerelease and the other one isn't -> lesser - return true; - } - else if(!thisPre && rhsPre) - { - // this isn't a prerelease and the other one is -> greater - return false; - } - else if(thisPre && rhsPre) - { - // both are prereleases - use natural compare... - return Strings::naturalCompare(prerelease, rhs.prerelease, Qt::CaseSensitive) < 0; - } - // neither is prerelease, so they are the same -> this cannot be less than rhs - return false; - } - else return Strings::naturalCompare(string, rhs.string, Qt::CaseSensitive) < 0; -} - -bool JavaVersion::operator==(const JavaVersion &rhs) -{ - if(parseable && rhs.parseable) - { - return major == rhs.major && minor == rhs.minor && security == rhs.security && prerelease == rhs.prerelease; - } - return string == rhs.string; -} - -bool JavaVersion::operator>(const JavaVersion &rhs) -{ - return (!operator<(rhs)) && (!operator==(rhs)); -} |