Make base58 validator explicit

This commit is contained in:
Wladimir J. van der Laan 2011-06-03 10:52:49 +02:00
parent 44384a4602
commit dab03e34f5
2 changed files with 27 additions and 6 deletions

View file

@ -3,7 +3,10 @@
#include <QRegExpValidator>
class BitcoinAddressValidator : public QRegExpValidator
/* Base48 entry widget validator.
Corrects near-miss characters and refuses characters that are no part of base48.
*/
class BitcoinAddressValidator : public QValidator
{
Q_OBJECT
public:

View file

@ -1,7 +1,5 @@
#include "bitcoinaddressvalidator.h"
#include "base58.h"
#include <QDebug>
/* Base58 characters are:
@ -18,12 +16,13 @@
*/
BitcoinAddressValidator::BitcoinAddressValidator(QObject *parent) :
QRegExpValidator(QRegExp(QString("^[")+QString(pszBase58)+QString("]+")), parent)
QValidator(parent)
{
}
QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) const
{
/* Correction */
for(int idx=0; idx<input.size(); ++idx)
{
switch(input.at(idx).unicode())
@ -39,7 +38,26 @@ QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) co
default:
break;
}
}
return QRegExpValidator::validate(input, pos);
/* Validation */
QValidator::State state = QValidator::Acceptable;
for(int idx=0; idx<input.size(); ++idx)
{
int ch = input.at(idx).unicode();
if(((ch >= '0' && ch<='9') ||
(ch >= 'a' && ch<='z') ||
(ch >= 'A' && ch<='Z')) &&
ch != 'l' && ch != 'I' && ch != '0' && ch != 'O')
{
/* Alphanumeric and not a 'forbidden' character */
}
else
{
state = QValidator::Invalid;
}
}
return state;
}