aboutsummaryrefslogtreecommitdiff
path: root/launcher/Version.h
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2023-01-19 21:59:33 -0300
committerflow <flowlnlnln@gmail.com>2023-01-20 11:15:26 -0300
commitbcebb1920ff5df4f2a311984b296bfd8d5969997 (patch)
treed0173ae00955976f58bed37a8f8f399b42a0faee /launcher/Version.h
parent81848e05f100a135ad1d307ccabb796be0540daa (diff)
downloadPrismLauncher-bcebb1920ff5df4f2a311984b296bfd8d5969997.tar.gz
PrismLauncher-bcebb1920ff5df4f2a311984b296bfd8d5969997.tar.bz2
PrismLauncher-bcebb1920ff5df4f2a311984b296bfd8d5969997.zip
refactor: clean up Section struct
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/Version.h')
-rw-r--r--launcher/Version.h128
1 files changed, 53 insertions, 75 deletions
diff --git a/launcher/Version.h b/launcher/Version.h
index b587319a..23481c29 100644
--- a/launcher/Version.h
+++ b/launcher/Version.h
@@ -36,15 +36,14 @@
#pragma once
#include <QDebug>
+#include <QList>
#include <QString>
#include <QStringView>
-#include <QList>
class QUrl;
-class Version
-{
-public:
+class Version {
+ public:
Version(QString str);
Version() = default;
@@ -55,125 +54,104 @@ public:
bool operator==(const Version &other) const;
bool operator!=(const Version &other) const;
- QString toString() const
- {
- return m_string;
- }
+ QString toString() const { return m_string; }
friend QDebug operator<<(QDebug debug, const Version& v);
-private:
- QString m_string;
- struct Section
- {
- explicit Section(const QString &fullString)
+ private:
+ struct Section {
+ explicit Section(QString fullString) : m_isNull(true), m_fullString(std::move(fullString))
{
- m_fullString = fullString;
- m_isNull = true;
int cutoff = m_fullString.size();
- for(int i = 0; i < m_fullString.size(); i++)
- {
- if(!m_fullString[i].isDigit())
- {
+ for (int i = 0; i < m_fullString.size(); i++) {
+ if (!m_fullString[i].isDigit()) {
cutoff = i;
break;
}
}
+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto numPart = QStringView{m_fullString}.left(cutoff);
#else
auto numPart = m_fullString.leftRef(cutoff);
#endif
- if(numPart.size())
- {
- numValid = true;
+
+ if (!numPart.isEmpty()) {
m_isNull = false;
m_numPart = numPart.toInt();
}
+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto stringPart = QStringView{m_fullString}.mid(cutoff);
#else
auto stringPart = m_fullString.midRef(cutoff);
#endif
- if(stringPart.size())
- {
+
+ if (!stringPart.isEmpty()) {
m_isNull = false;
m_stringPart = stringPart.toString();
}
}
- explicit Section() {}
- bool numValid = false;
+
+ explicit Section() = default;
+
+ bool m_isNull = false;
int m_numPart = 0;
+
QString m_stringPart;
QString m_fullString;
- bool m_isNull;
- inline bool operator!=(const Section &other) const
+ inline bool operator==(const Section& other) const
{
- if (m_isNull && other.numValid) {
- return 0 != other.m_numPart;
- } else if (numValid && other.m_isNull) {
- return m_numPart != 0;
- } else if (m_isNull || other.m_isNull) {
- if ((m_stringPart == ".") || (other.m_stringPart == ".")) return false;
- return true;
- }
- if(numValid && other.numValid)
- {
- return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart;
- }
- else
- {
- return m_fullString != other.m_fullString;
- }
+ if (m_isNull && !other.m_isNull)
+ return other.m_numPart == 0;
+
+ if (!m_isNull && other.m_isNull)
+ return m_numPart == 0;
+
+ if (m_isNull || other.m_isNull)
+ return (m_stringPart == ".") || (other.m_stringPart == ".");
+
+ if (!m_isNull && !other.m_isNull)
+ return (m_numPart == other.m_numPart) && (m_stringPart == other.m_stringPart);
+
+ return m_fullString == other.m_fullString;
}
+
inline bool operator<(const Section &other) const
{
- if (m_isNull && other.numValid) {
- return 0 < other.m_numPart;
- } else if (numValid && other.m_isNull) {
+ if (m_isNull && !other.m_isNull)
+ return other.m_numPart > 0;
+
+ if (!m_isNull && other.m_isNull)
return m_numPart < 0;
- } else if (m_isNull || other.m_isNull) {
+
+ if (m_isNull || other.m_isNull)
return true;
- }
- if(numValid && other.numValid)
- {
+
+ if (!m_isNull && !other.m_isNull) {
if(m_numPart < other.m_numPart)
return true;
if(m_numPart == other.m_numPart && m_stringPart < other.m_stringPart)
return true;
return false;
}
- else
- {
- return m_fullString < other.m_fullString;
- }
+
+ return m_fullString < other.m_fullString;
+ }
+
+ inline bool operator!=(const Section& other) const
+ {
+ return !(*this == other);
}
inline bool operator>(const Section &other) const
{
- if (m_isNull && other.numValid) {
- return 0 > other.m_numPart;
- } else if (numValid && other.m_isNull) {
- return m_numPart > 0;
- } else if (m_isNull || other.m_isNull) {
- return false;
- }
- if(numValid && other.numValid)
- {
- if(m_numPart > other.m_numPart)
- return true;
- if(m_numPart == other.m_numPart && m_stringPart > other.m_stringPart)
- return true;
- return false;
- }
- else
- {
- return m_fullString > other.m_fullString;
- }
+ return !(*this < other || *this == other);
}
};
-
+ private:
+ QString m_string;
QList<Section> m_sections;
void parse();