PrismLauncher/launcher/Version.h

115 lines
3.0 KiB
C
Raw Normal View History

#pragma once
#include <QString>
#include <QStringView>
2014-09-06 17:16:56 +01:00
#include <QList>
class QUrl;
class Version
{
public:
2018-07-15 13:51:05 +01:00
Version(const QString &str);
Version() {}
2018-07-15 13:51:05 +01:00
bool operator<(const Version &other) const;
bool operator<=(const Version &other) const;
bool operator>(const Version &other) const;
bool operator>=(const Version &other) const;
bool operator==(const Version &other) const;
bool operator!=(const Version &other) const;
2018-07-15 13:51:05 +01:00
QString toString() const
{
return m_string;
}
private:
2018-07-15 13:51:05 +01:00
QString m_string;
struct Section
{
explicit Section(const QString &fullString)
{
m_fullString = fullString;
int cutoff = m_fullString.size();
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
2018-07-15 13:51:05 +01:00
auto numPart = m_fullString.leftRef(cutoff);
#endif
2018-07-15 13:51:05 +01:00
if(numPart.size())
{
numValid = true;
m_numPart = numPart.toInt();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto stringPart = QStringView{m_fullString}.mid(cutoff);
#else
2018-07-15 13:51:05 +01:00
auto stringPart = m_fullString.midRef(cutoff);
#endif
2018-07-15 13:51:05 +01:00
if(stringPart.size())
{
m_stringPart = stringPart.toString();
}
}
explicit Section() {}
bool numValid = false;
int m_numPart = 0;
QString m_stringPart;
QString m_fullString;
2014-09-06 17:16:56 +01:00
2018-07-15 13:51:05 +01:00
inline bool operator!=(const Section &other) const
{
if(numValid && other.numValid)
{
return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart;
}
else
{
return m_fullString != other.m_fullString;
}
}
inline bool operator<(const Section &other) const
{
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;
}
}
inline bool operator>(const Section &other) const
{
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;
}
}
};
QList<Section> m_sections;
2014-09-06 17:16:56 +01:00
2018-07-15 13:51:05 +01:00
void parse();
};