File indexing completed on 2024-04-21 15:55:43

0001 /**************************************************************************
0002 *   Copyright (C) 2006 by Michel Ludwig (michel.ludwig@kdemail.net)       *
0003 ***************************************************************************/
0004 
0005 /**************************************************************************
0006 *                                                                         *
0007 *   This program is free software; you can redistribute it and/or modify  *
0008 *   it under the terms of the GNU General Public License as published by  *
0009 *   the Free Software Foundation; either version 2 of the License, or     *
0010 *   (at your option) any later version.                                   *
0011 *                                                                         *
0012 ***************************************************************************/
0013 
0014 #include "kileversion.h"
0015 
0016 #include <QStringList>
0017 
0018 int compareVersionStrings(const QString& s1, const QString& s2) {
0019     QStringList l1 = s1.split('.');
0020     QStringList l2 = s2.split('.');
0021     while(l1.size() < 3) {
0022         l1.push_back("0");
0023     }
0024     while(l2.size() < 3) {
0025         l2.push_back("0");
0026     }
0027     QStringList::iterator i1 = l1.begin();
0028     QStringList::iterator i2 = l2.begin();
0029     for(unsigned int i = 0; i < 3; ++i) {
0030         unsigned int c1 = (*i1).toUInt();
0031         unsigned int c2 = (*i2).toUInt();
0032         if(c1 < c2) {
0033             return -1;
0034         }
0035         else if(c1 > c2) {
0036             return 1;
0037         }
0038         ++i1;
0039         ++i2;
0040     }
0041     return 0;
0042 }