1
/**********************************************************************
2
** Copyright (C) 2000 Trolltech AS. All rights reserved.
4
** This file is part of Qt Designer.
6
** This file may be distributed and/or modified under the terms of the
7
** GNU General Public License version 2 as published by the Free Software
8
** Foundation and appearing in the file LICENSE.GPL included in the
9
** packaging of this file.
11
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12
** licenses may use this file in accordance with the Qt Commercial License
13
** Agreement provided with the Software.
15
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18
** See http://www.trolltech.com/gpl/ for GPL licensing information.
19
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20
** information about Qt Commercial License Agreements.
22
** Contact info@trolltech.com if any conditions of this licensing are
25
**********************************************************************/
27
#include "asciivalidator.h"
31
AsciiValidator::AsciiValidator( QObject * parent, const char *name )
32
: QValidator( parent, name ), functionName( FALSE )
36
AsciiValidator::AsciiValidator( bool funcName, QObject * parent, const char *name )
37
: QValidator( parent, name ), functionName( funcName )
41
AsciiValidator::AsciiValidator( const QString &allow, QObject * parent, const char *name )
42
: QValidator( parent, name ), functionName( FALSE ), allowedChars( allow )
46
AsciiValidator::~AsciiValidator()
50
QValidator::State AsciiValidator::validate( QString &s, int & ) const
53
bool outParen = FALSE;
54
if ( !s.isEmpty() && s[0].row() == 0 && s[0].cell() >= '0' && s[0].cell() <= '9' )
56
for ( int i = 0, j = 0; i < (int) s.length(); i++ ) {
58
uchar c = s[i].cell();
60
if ( outParen ) { // check if we have 'const' or 'volatile'
61
static const QString con = " const";
62
static const QString vol = " volatile";
63
QString mid = s.mid( j );
64
if ( !( con.startsWith( mid ) || vol.startsWith( mid ) ) )
65
return QValidator::Invalid;
68
if ( inParen && c != ')' )
71
if ( r == 0 && ( ( c >= '0' && c <= '9' ) ||
72
( c >= 'a' && c <= 'z' ) ||
73
( c >= 'A' && c <= 'Z' ) ) )
88
if ( allowedChars.find( s[ i ] ) != -1 )
93
return QValidator::Acceptable;