diff --git a/versionnumber.cpp b/versionnumber.cpp index 37149a3b..bc7c8195 100644 --- a/versionnumber.cpp +++ b/versionnumber.cpp @@ -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); @@ -150,6 +150,7 @@ 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) { @@ -157,12 +158,14 @@ int VersionNumber::compare(const QStringList &first, const QStringList &second) } 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 { diff --git a/versionnumber.h b/versionnumber.h index 529036eb..bcf434e2 100644 --- a/versionnumber.h +++ b/versionnumber.h @@ -81,12 +81,12 @@ 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 @@ -94,13 +94,14 @@ class VersionNumber 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, -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)