2014-02-02 13:05:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QString>
|
2014-09-06 17:16:56 +01:00
|
|
|
#include <QList>
|
|
|
|
|
2014-02-02 13:05:07 +00:00
|
|
|
#include "libutil_config.h"
|
|
|
|
|
|
|
|
class QUrl;
|
|
|
|
|
|
|
|
namespace Util
|
|
|
|
{
|
|
|
|
struct Version
|
|
|
|
{
|
|
|
|
Version(const QString &str);
|
2014-09-06 17:16:56 +01:00
|
|
|
Version() {}
|
2014-02-02 13:05:07 +00:00
|
|
|
|
|
|
|
bool operator<(const Version &other) const;
|
|
|
|
bool operator<=(const Version &other) const;
|
|
|
|
bool operator>(const Version &other) const;
|
2014-09-06 17:16:56 +01:00
|
|
|
bool operator>=(const Version &other) const;
|
2014-02-02 13:05:07 +00:00
|
|
|
bool operator==(const Version &other) const;
|
|
|
|
bool operator!=(const Version &other) const;
|
|
|
|
|
|
|
|
QString toString() const
|
|
|
|
{
|
|
|
|
return m_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_string;
|
2014-09-06 17:16:56 +01:00
|
|
|
struct Section
|
|
|
|
{
|
2015-01-27 21:31:07 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto numPart = m_fullString.leftRef(cutoff);
|
|
|
|
if(numPart.size())
|
|
|
|
{
|
|
|
|
numValid = true;
|
|
|
|
m_numPart = numPart.toInt();
|
|
|
|
}
|
|
|
|
auto stringPart = m_fullString.midRef(cutoff);
|
|
|
|
if(stringPart.size())
|
|
|
|
{
|
|
|
|
m_stringPart = stringPart.toString();
|
|
|
|
}
|
|
|
|
}
|
2014-09-06 17:16:56 +01:00
|
|
|
explicit Section() {}
|
2015-01-27 21:31:07 +00:00
|
|
|
bool numValid = false;
|
|
|
|
int m_numPart = 0;
|
|
|
|
QString m_stringPart;
|
|
|
|
QString m_fullString;
|
2014-09-06 17:16:56 +01:00
|
|
|
|
|
|
|
inline bool operator!=(const Section &other) const
|
|
|
|
{
|
2015-01-27 21:31:07 +00:00
|
|
|
if(numValid && other.numValid)
|
|
|
|
{
|
|
|
|
return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_fullString != other.m_fullString;
|
|
|
|
}
|
2014-09-06 17:16:56 +01:00
|
|
|
}
|
|
|
|
inline bool operator<(const Section &other) const
|
|
|
|
{
|
2015-01-27 21:31:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-09-06 17:16:56 +01:00
|
|
|
}
|
|
|
|
inline bool operator>(const Section &other) const
|
|
|
|
{
|
2015-01-27 21:31:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-09-06 17:16:56 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
QList<Section> m_sections;
|
|
|
|
|
|
|
|
void parse();
|
2014-02-02 13:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LIBUTIL_EXPORT bool versionIsInInterval(const QString &version, const QString &interval);
|
2014-09-06 17:16:56 +01:00
|
|
|
LIBUTIL_EXPORT bool versionIsInInterval(const Version &version, const QString &interval);
|
2014-02-02 13:05:07 +00:00
|
|
|
}
|
|
|
|
|