summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/utils.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-30 21:59:47 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-30 21:59:47 +0000
commit10b8e327d8c0d37b8a9f1997e33e4bf1a97bb39b (patch)
tree96787bf458cec93c63bfd37904388450ce32052a /rbutil/rbutilqt/base/utils.cpp
parent35150b6dcb18089ba76a660e6b73caf1dad86579 (diff)
downloadrockbox-10b8e327d8c0d37b8a9f1997e33e4bf1a97bb39b.tar.gz
rockbox-10b8e327d8c0d37b8a9f1997e33e4bf1a97bb39b.zip
FS#11439: Fix version comparison regression.
Improve string suffix handling by distinguishing between version number separators (i.e. dots) and extended separators and additional version characters. Corrects false update information displayed for 64bit binaries of Rockbox Utility. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27201 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/base/utils.cpp')
-rw-r--r--rbutil/rbutilqt/base/utils.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp
index 1452ada330..bd2bce0609 100644
--- a/rbutil/rbutilqt/base/utils.cpp
+++ b/rbutil/rbutilqt/base/utils.cpp
@@ -211,9 +211,9 @@ QString Utils::checkEnvironment(bool permission)
*/
int Utils::compareVersionStrings(QString s1, QString s2)
{
+ qDebug() << "[Utils] comparing version strings" << s1 << "and" << s2;
QString a = s1.trimmed();
QString b = s2.trimmed();
- qDebug() << "[Utils] comparing version strings" << a << "and" << b;
// if strings are identical return 0.
if(a.isEmpty())
return 1;
@@ -252,8 +252,19 @@ int Utils::compareVersionStrings(QString s1, QString s2)
a.remove(QRegExp("^\\d*"));
b.remove(QRegExp("^\\d*"));
+ // If only one of the following characters is a dot that one is
+ // "greater" then anything else. Make sure it's followed by a number,
+ // Otherwise it might be the end of the string or suffix. Do this
+ // before version addon characters check to avoid stopping too early.
+ bool adot = a.contains(QRegExp("^[a-zA-Z]*\\.[0-9]"));
+ bool bdot = b.contains(QRegExp("^[a-zA-Z]*\\.[0-9]"));
+ if(adot && !bdot)
+ return -1;
+ if(!adot && bdot)
+ return 1;
// if number is immediately followed by a character consider it as
- // version addon (like 1.2.3b). In this case compare characters too.
+ // version addon (like 1.2.3b). In this case compare characters and end
+ // (version numbers like 1.2b.3 aren't handled).
QChar ltra;
QChar ltrb;
if(a.contains(QRegExp("^[a-zA-Z]")))
@@ -262,6 +273,7 @@ int Utils::compareVersionStrings(QString s1, QString s2)
ltrb = b.at(0);
if(ltra != ltrb)
return (ltra < ltrb) ? 1 : -1;
+
// both are identical or no addon characters, ignore.
// remove modifiers and following dot.
a.remove(QRegExp("^[a-zA-Z]*\\."));