From 791221e923586bb717396ecf18bd13e57034df99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 27 Jan 2015 22:31:07 +0100 Subject: NOISSUE Refactors and moving of things --- depends/util/include/modutils.h | 68 ++++++++++++++++++++++++++++++++++++----- depends/util/src/modutils.cpp | 23 +++++--------- 2 files changed, 67 insertions(+), 24 deletions(-) (limited to 'depends') diff --git a/depends/util/include/modutils.h b/depends/util/include/modutils.h index 1fecd4d5..bc608f96 100644 --- a/depends/util/include/modutils.h +++ b/depends/util/include/modutils.h @@ -30,24 +30,76 @@ private: QString m_string; struct Section { - explicit Section(const QString &str, const int num) : numValid(true), number(num), string(str) {} - explicit Section(const QString &str) : numValid(false), string(str) {} + 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(); + } + } explicit Section() {} - bool numValid; - int number; - QString string; + bool numValid = false; + int m_numPart = 0; + QString m_stringPart; + QString m_fullString; inline bool operator!=(const Section &other) const { - return (numValid && other.numValid) ? (number != other.number) : (string != other.string); + if(numValid && other.numValid) + { + return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart; + } + else + { + return m_fullString != other.m_fullString; + } } inline bool operator<(const Section &other) const { - return (numValid && other.numValid) ? (number < other.number) : (string < other.string); + 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; + } } inline bool operator>(const Section &other) const { - return (numValid && other.numValid) ? (number > other.number) : (string > other.string); + 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; + } } }; QList
m_sections; diff --git a/depends/util/src/modutils.cpp b/depends/util/src/modutils.cpp index 67c09dec..5f89eacd 100644 --- a/depends/util/src/modutils.cpp +++ b/depends/util/src/modutils.cpp @@ -15,9 +15,9 @@ bool Util::Version::operator<(const Version &other) const const int size = qMax(m_sections.size(), other.m_sections.size()); for (int i = 0; i < size; ++i) { - const Section sec1 = (i >= m_sections.size()) ? Section("0", 0) : m_sections.at(i); + const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i); const Section sec2 = - (i >= other.m_sections.size()) ? Section("0", 0) : other.m_sections.at(i); + (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i); if (sec1 != sec2) { return sec1 < sec2; @@ -35,9 +35,9 @@ bool Util::Version::operator>(const Version &other) const const int size = qMax(m_sections.size(), other.m_sections.size()); for (int i = 0; i < size; ++i) { - const Section sec1 = (i >= m_sections.size()) ? Section("0", 0) : m_sections.at(i); + const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i); const Section sec2 = - (i >= other.m_sections.size()) ? Section("0", 0) : other.m_sections.at(i); + (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i); if (sec1 != sec2) { return sec1 > sec2; @@ -55,9 +55,9 @@ bool Util::Version::operator==(const Version &other) const const int size = qMax(m_sections.size(), other.m_sections.size()); for (int i = 0; i < size; ++i) { - const Section sec1 = (i >= m_sections.size()) ? Section("0", 0) : m_sections.at(i); + const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i); const Section sec2 = - (i >= other.m_sections.size()) ? Section("0", 0) : other.m_sections.at(i); + (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i); if (sec1 != sec2) { return false; @@ -79,16 +79,7 @@ void Util::Version::parse() for (const auto part : parts) { - bool ok = false; - int num = part.toInt(&ok); - if (ok) - { - m_sections.append(Section(part, num)); - } - else - { - m_sections.append(Section(part)); - } + m_sections.append(Section(part)); } } -- cgit v1.2.3