Skip to content

Commit

Permalink
Minor edit
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianTM committed Feb 19, 2024
1 parent 0b144f3 commit d51d5a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
15 changes: 9 additions & 6 deletions versionnumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ void VersionNumber::setStrings(const QString &value)
QString debian_str;

// Parse epoch and upstream_version
if (value.contains(QLatin1Char(':'))) {
epoch = value.section(QLatin1Char(':'), 0, 0).toInt();
upstream_str = value.section(QLatin1Char(':'), 1);
if (value.contains(':')) {
epoch = value.section(':', 0, 0).toInt();
upstream_str = value.section(':', 1);
} else {
epoch = 0;
upstream_str = value;
}

// Parse debian_revision
if (upstream_str.contains(QLatin1Char('-'))) {
debian_str = upstream_str.section(QLatin1Char('-'), -1);
upstream_str = upstream_str.remove(QLatin1Char('-') + debian_str);
if (upstream_str.contains('-')) {
debian_str = upstream_str.section('-', -1);
upstream_str = upstream_str.remove('-' + debian_str);
}

upstream_version = groupDigits(upstream_str);
Expand Down Expand Up @@ -150,19 +150,22 @@ int VersionNumber::compare(const QStringList &first, const QStringList &second)
return -1;
}

// if one char length check which one is larger
if (first.at(i).length() == 1 && second.at(i).length() == 1) {
int res = compare(first.at(i).at(0), second.at(i).at(0));
if (res == 0) {
continue;
} else {
return res;
}
// one char (not-number) vs. multiple (digits)
} else if (first.at(i).length() > 1 && second.at(i).length() == 1 && !second.at(i).at(0).isDigit()) {
return 1;
} else if (first.at(i).length() == 1 && !first.at(i).at(0).isDigit() && second.at(i).length() > 1) {
return -1;
}

// Compare remaining digits
if (second.at(i).toInt() > first.at(i).toInt()) {
return 1;
} else {
Expand Down
23 changes: 12 additions & 11 deletions versionnumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,27 @@ class VersionNumber
VersionNumber &operator=(const VersionNumber &value) = default;
VersionNumber &operator=(const QString &value);

bool operator<(const VersionNumber &value) const;
bool operator<=(const VersionNumber &value) const;
bool operator>(const VersionNumber &value) const;
bool operator>=(const VersionNumber &value) const;
bool operator==(const VersionNumber &value) const;
bool operator!=(const VersionNumber &value) const;
[[nodiscard]] bool operator<(const VersionNumber &value) const;
[[nodiscard]] bool operator<=(const VersionNumber &value) const;
[[nodiscard]] bool operator>(const VersionNumber &value) const;
[[nodiscard]] bool operator>=(const VersionNumber &value) const;
[[nodiscard]] bool operator==(const VersionNumber &value) const;
[[nodiscard]] bool operator!=(const VersionNumber &value) const;

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

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

[[nodiscard]] int compare(const VersionNumber &first,
const VersionNumber &second) const; // 1 for >second, -1 for <second, 0 for equal
static int compare(const QStringList &first, const QStringList &second);
static int compare(QChar first, QChar second);
// 1 for > second, -1 for < second, 0 for equal
[[nodiscard]] int compare(const VersionNumber &first, const VersionNumber &second) const;
[[nodiscard]] static int compare(const QStringList &first, const QStringList &second);
[[nodiscard]] static int compare(QChar first, QChar second);
};

Q_DECLARE_METATYPE(VersionNumber)

0 comments on commit d51d5a6

Please sign in to comment.