Validation version.
--HG-- branch : feature
This commit is contained in:
parent
51b89a5497
commit
71f070a509
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ private:
|
|||
QString fileName;
|
||||
|
||||
QString GetVersionStr() const;
|
||||
void ValidateVersion(QString &versionStr) const;
|
||||
};
|
||||
|
||||
#endif // VABSTRACTCONVERTER_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user