KAlarm Library
version.cpp
00001 /* 00002 * version.cpp - program version functions 00003 * This file is part of kalarmcal library, which provides access to KAlarm 00004 * calendar data. 00005 * Copyright © 2002-2007,2011 by David Jarvie <djarvie@kde.org> 00006 * 00007 * This library is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU Library General Public License as published 00009 * by the Free Software Foundation; either version 2 of the License, or (at 00010 * your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00015 * License for more details. 00016 * 00017 * You should have received a copy of the GNU Library General Public License 00018 * along with this library; see the file COPYING.LIB. If not, write to the 00019 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00020 * MA 02110-1301, USA. 00021 */ 00022 00023 #include "version.h" 00024 00025 namespace KAlarmCal 00026 { 00027 00028 int Version(int major, int minor, int rev) 00029 { 00030 return major*10000 + minor*100 + rev; 00031 } 00032 00033 /****************************************************************************** 00034 * Convert the supplied KAlarm version string to a version number. 00035 * Reply = version number (double digit for each of major, minor & issue number, 00036 * e.g. 010203 for 1.2.3 00037 * = 0 if invalid version string. 00038 */ 00039 int getVersionNumber(const QString& version, QString* subVersion) 00040 { 00041 // N.B. Remember to change Version(int major, int minor, int rev) 00042 // if the representation returned by this method changes. 00043 if (subVersion) 00044 subVersion->clear(); 00045 int count = version.count(QChar('.')) + 1; 00046 if (count < 2) 00047 return 0; 00048 bool ok; 00049 unsigned vernum = version.section('.', 0, 0).toUInt(&ok) * 10000; // major version 00050 if (!ok) 00051 return 0; 00052 unsigned v = version.section('.', 1, 1).toUInt(&ok); // minor version 00053 if (!ok) 00054 return 0; 00055 vernum += (v < 99 ? v : 99) * 100; 00056 if (count >= 3) 00057 { 00058 // Issue number: allow other characters to follow the last digit 00059 QString issue = version.section('.', 2); 00060 int n = issue.length(); 00061 if (!n || !issue[0].isDigit()) 00062 return 0; 00063 int i; 00064 for (i = 0; i < n && issue[i].isDigit(); ++i) ; 00065 if (subVersion) 00066 *subVersion = issue.mid(i); 00067 v = issue.left(i).toUInt(); // issue number 00068 vernum += (v < 99 ? v : 99); 00069 } 00070 return vernum; 00071 } 00072 00073 QString getVersionString(int version) 00074 { 00075 return QString("%1.%2.%3").arg(version/10000).arg((version%10000)/100).arg(version%100); 00076 } 00077 00078 } // namespace KAlarmCal 00079 00080 // vim: et sw=4:
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:50:08 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:50:08 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.