summaryrefslogtreecommitdiffstats
path: root/src/kile/kileversion.cpp
blob: cc45df1fde0191d42b220c032b795bbfa09caf76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**************************************************************************
*   Copyright (C) 2006 by Michel Ludwig (michel.ludwig@kdemail.net)       *
***************************************************************************/

/**************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/

#include "kileversion.h"

#include <qstringlist.h>

int compareVersionStrings(const QString& s1, const QString& s2) {
	QStringList l1 = QStringList::split(".", s1);
	QStringList l2 = QStringList::split(".", s2);
	while(l1.size() < 3) {
		l1.push_back("0");
	}
	while(l2.size() < 3) {
		l2.push_back("0");
	}
	QStringList::iterator i1 = l1.begin();
	QStringList::iterator i2 = l2.begin();
	for(unsigned int i = 0; i < 3; ++i) {
		unsigned int c1 = (*i1).toUInt();
		unsigned int c2 = (*i2).toUInt();
		if(c1 < c2) {
			return -1;
		}
		else if(c1 > c2) {
			return 1;
		}
		++i1;
		++i2;
	}
	return 0;
}