1
/***************************************************************************
2
* Copyright (C) 2005 by Adam Treat *
5
* Copyright (C) 2004 by Scott Wheeler *
8
* This program is free software; you can redistribute it and/or modify *
9
* it under the terms of the GNU General Public License as published by *
10
* the Free Software Foundation; either version 2 of the License, or *
11
* (at your option) any later version. *
13
***************************************************************************/
15
#include "asciivalidator.h"
19
AsciiValidator::AsciiValidator( QObject * parent, const char *name )
20
: QValidator( parent, name ), functionName( false )
23
AsciiValidator::AsciiValidator( bool funcName, QObject * parent, const char *name )
24
: QValidator( parent, name ), functionName( funcName )
27
AsciiValidator::AsciiValidator( const QString &allow, QObject * parent, const char *name )
28
: QValidator( parent, name ), functionName( false ), allowedChars( allow )
31
AsciiValidator::~AsciiValidator()
34
QValidator::State AsciiValidator::validate( QString &s, int & ) const
37
bool outParen = false;
38
if ( !s.isEmpty() && s[ 0 ].row() == 0 && s[ 0 ].cell() >= '0' && s[ 0 ].cell() <= '9' )
40
for ( int i = 0, j = 0; i < ( int ) s.length(); i++ )
42
uchar r = s[ i ].row();
43
uchar c = s[ i ].cell();
46
{ // check if we have 'const' or 'volatile'
47
static const QString con = " const";
48
static const QString vol = " volatile";
49
QString mid = s.mid( j );
50
if ( !( con.startsWith( mid ) || vol.startsWith( mid ) ) )
51
return QValidator::Invalid;
54
if ( inParen && c != ')' )
57
if ( r == 0 && ( ( c >= '0' && c <= '9' ) ||
58
( c >= 'a' && c <= 'z' ) ||
59
( c >= 'A' && c <= 'Z' ) ) )
77
if ( allowedChars.find( s[ i ] ) != -1 )
82
return QValidator::Acceptable;
85
#include "asciivalidator.moc"