Skip to content

Commit d51d5a6

Browse files
committed
Minor edit
1 parent 0b144f3 commit d51d5a6

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

versionnumber.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ void VersionNumber::setStrings(const QString &value)
3939
QString debian_str;
4040

4141
// Parse epoch and upstream_version
42-
if (value.contains(QLatin1Char(':'))) {
43-
epoch = value.section(QLatin1Char(':'), 0, 0).toInt();
44-
upstream_str = value.section(QLatin1Char(':'), 1);
42+
if (value.contains(':')) {
43+
epoch = value.section(':', 0, 0).toInt();
44+
upstream_str = value.section(':', 1);
4545
} else {
4646
epoch = 0;
4747
upstream_str = value;
4848
}
4949

5050
// Parse debian_revision
51-
if (upstream_str.contains(QLatin1Char('-'))) {
52-
debian_str = upstream_str.section(QLatin1Char('-'), -1);
53-
upstream_str = upstream_str.remove(QLatin1Char('-') + debian_str);
51+
if (upstream_str.contains('-')) {
52+
debian_str = upstream_str.section('-', -1);
53+
upstream_str = upstream_str.remove('-' + debian_str);
5454
}
5555

5656
upstream_version = groupDigits(upstream_str);
@@ -150,19 +150,22 @@ int VersionNumber::compare(const QStringList &first, const QStringList &second)
150150
return -1;
151151
}
152152

153+
// if one char length check which one is larger
153154
if (first.at(i).length() == 1 && second.at(i).length() == 1) {
154155
int res = compare(first.at(i).at(0), second.at(i).at(0));
155156
if (res == 0) {
156157
continue;
157158
} else {
158159
return res;
159160
}
161+
// one char (not-number) vs. multiple (digits)
160162
} else if (first.at(i).length() > 1 && second.at(i).length() == 1 && !second.at(i).at(0).isDigit()) {
161163
return 1;
162164
} else if (first.at(i).length() == 1 && !first.at(i).at(0).isDigit() && second.at(i).length() > 1) {
163165
return -1;
164166
}
165167

168+
// Compare remaining digits
166169
if (second.at(i).toInt() > first.at(i).toInt()) {
167170
return 1;
168171
} else {

versionnumber.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,27 @@ class VersionNumber
8181
VersionNumber &operator=(const VersionNumber &value) = default;
8282
VersionNumber &operator=(const QString &value);
8383

84-
bool operator<(const VersionNumber &value) const;
85-
bool operator<=(const VersionNumber &value) const;
86-
bool operator>(const VersionNumber &value) const;
87-
bool operator>=(const VersionNumber &value) const;
88-
bool operator==(const VersionNumber &value) const;
89-
bool operator!=(const VersionNumber &value) const;
84+
[[nodiscard]] bool operator<(const VersionNumber &value) const;
85+
[[nodiscard]] bool operator<=(const VersionNumber &value) const;
86+
[[nodiscard]] bool operator>(const VersionNumber &value) const;
87+
[[nodiscard]] bool operator>=(const VersionNumber &value) const;
88+
[[nodiscard]] bool operator==(const VersionNumber &value) const;
89+
[[nodiscard]] bool operator!=(const VersionNumber &value) const;
9090

9191
private:
9292
QString str; // Full version string
9393
int epoch {};
9494
QStringList upstream_version; // A string list of characters, numbers are grouped together
9595
QStringList debian_revision;
9696

97-
static QStringList groupDigits(const QString &value); // Add characters to separate elements, groups digits together
97+
// Add characters to separate elements, groups digits together
98+
[[nodiscard]] static QStringList groupDigits(const QString &value);
9899
void setStrings(const QString &value);
99100

100-
[[nodiscard]] int compare(const VersionNumber &first,
101-
const VersionNumber &second) const; // 1 for >second, -1 for <second, 0 for equal
102-
static int compare(const QStringList &first, const QStringList &second);
103-
static int compare(QChar first, QChar second);
101+
// 1 for > second, -1 for < second, 0 for equal
102+
[[nodiscard]] int compare(const VersionNumber &first, const VersionNumber &second) const;
103+
[[nodiscard]] static int compare(const QStringList &first, const QStringList &second);
104+
[[nodiscard]] static int compare(QChar first, QChar second);
104105
};
105106

106107
Q_DECLARE_METATYPE(VersionNumber)

0 commit comments

Comments
 (0)