mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-09 21:42:13 +00:00
36 lines
880 B
C++
36 lines
880 B
C++
|
|
#include "idvalidator.hpp"
|
|
|
|
bool CSVWorld::IdValidator::isValid (const QChar& c, bool first) const
|
|
{
|
|
if (c.isLetter() || c=='_')
|
|
return true;
|
|
|
|
if (!first && (c.isDigit() || c.isSpace()))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
CSVWorld::IdValidator::IdValidator (bool relaxed, QObject *parent)
|
|
: QValidator (parent), mRelaxed (relaxed)
|
|
{}
|
|
|
|
QValidator::State CSVWorld::IdValidator::validate (QString& input, int& pos) const
|
|
{
|
|
if (mRelaxed)
|
|
{
|
|
if (input.indexOf ('"')!=-1 || input.indexOf ("::")!=-1 || input.indexOf ("#")!=-1)
|
|
return QValidator::Invalid;
|
|
}
|
|
else
|
|
{
|
|
bool first = true;
|
|
|
|
for (QString::const_iterator iter (input.begin()); iter!=input.end(); ++iter, first = false)
|
|
if (!isValid (*iter, first))
|
|
return QValidator::Invalid;
|
|
}
|
|
|
|
return QValidator::Acceptable;
|
|
} |