Validation version.

--HG--
branch : feature
This commit is contained in:
dismine 2014-12-11 18:14:02 +02:00
parent 51b89a5497
commit 71f070a509
2 changed files with 25 additions and 0 deletions

View File

@ -29,12 +29,16 @@
#include "vabstractconverter.h"
#include "exception/vexception.h"
#include <QRegExpValidator>
//---------------------------------------------------------------------------------------------------------------------
VAbstractConverter::VAbstractConverter(const QString &fileName)
:VDomDocument(), fileName(fileName)
{
this->setXMLContent(fileName);
QString version = GetVersionStr();
ValidateVersion(version);
}
//---------------------------------------------------------------------------------------------------------------------
@ -64,3 +68,23 @@ QString VAbstractConverter::GetVersionStr() const
}
return QString(QStringLiteral("0.0.0"));
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractConverter::ValidateVersion(QString &versionStr) const
{
int pos = 0;
QRegExp rx(QStringLiteral("^(0|([1-9][0-9]*)).(0|([1-9][0-9]*)).(0|([1-9][0-9]*))$"));
QRegExpValidator v(rx, 0);
if (v.validate(versionStr, pos) != QValidator::Acceptable)
{
const QString errorMsg(tr("Version \"%1\" invalid.").arg(versionStr));
throw VException(errorMsg);
}
if (versionStr == QLatin1String("0.0.0"))
{
const QString errorMsg(tr("Version \"0.0.0\" invalid."));
throw VException(errorMsg);
}
}

View File

@ -43,6 +43,7 @@ private:
QString fileName;
QString GetVersionStr() const;
void ValidateVersion(QString &versionStr) const;
};
#endif // VABSTRACTCONVERTER_H