/**************************************************************************
*   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 <tqstringlist.h>

int compareVersionStrings(const TQString& s1, const TQString& s2) {
	TQStringList l1 = TQStringList::split(".", s1);
	TQStringList l2 = TQStringList::split(".", s2);
	while(l1.size() < 3) {
		l1.push_back("0");
	}
	while(l2.size() < 3) {
		l2.push_back("0");
	}
	TQStringList::iterator i1 = l1.begin();
	TQStringList::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;
}

