forked from MUME/MMapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareVersion.cpp
More file actions
45 lines (39 loc) · 1.2 KB
/
Copy pathCompareVersion.cpp
File metadata and controls
45 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2019 The MMapper Authors
// Author: Nils Schimmelmann <nschimme@gmail.com> (Jahara)
#include "CompareVersion.h"
#include <QRegularExpression>
CompareVersion::CompareVersion(const QString &versionStr) noexcept
{
static const QRegularExpression versionRx(R"(v?(\d+)\.(\d+)\.(\d+))");
auto result = versionRx.match(versionStr);
if (result.hasMatch()) {
m_parts[0] = result.captured(1).toInt();
m_parts[1] = result.captured(2).toInt();
m_parts[2] = result.captured(3).toInt();
}
}
bool CompareVersion::operator>(const CompareVersion &other) const
{
for (size_t i = 0; i < m_parts.size(); ++i) {
auto myPart = m_parts.at(i);
auto otherPart = other.m_parts.at(i);
if (myPart == otherPart) {
continue;
}
if (myPart > otherPart) {
return true;
}
break;
}
return false;
}
bool CompareVersion::operator==(const CompareVersion &other) const
{
return m_parts == other.m_parts;
}
QString CompareVersion::toQString() const
{
const auto &parts = m_parts;
return QString("%1.%2.%3").arg(parts.at(0)).arg(parts.at(1)).arg(parts.at(2));
}