4 Copyright (c) 2001 Marc Mutz <mutz@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; version 2.0
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with this library; if not, write to the Free
18 Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA
22 #include "kstringvalidator.h"
26 // KStringListValidator
29 QValidator::State
KStringListValidator::validate( QString
& input
, int& ) const {
30 if ( input
.isEmpty() ) return Intermediate
;
32 if ( isRejecting() ) // anything not in mStringList is acceptable:
33 if ( mStringList
.find( input
) == mStringList
.end() )
37 else // only what is in mStringList is acceptable:
38 if ( mStringList
.find( input
) != mStringList
.end() )
41 for ( QStringList::ConstIterator it
= mStringList
.begin() ;
42 it
!= mStringList
.end() ; ++it
)
43 if ( (*it
).startsWith( input
) || input
.startsWith( *it
) )
49 void KStringListValidator::fixup( QString
& /* input */ ) const {
50 if ( !isFixupEnabled() ) return;
51 // warn (but only once!) about non-implemented fixup():
52 static bool warn
= true;
54 kdDebug() << "KStringListValidator::fixup() isn't yet implemented!"
64 #define ALLOWED_CHARS "!#-'*+.0-9^-~+-"
66 QValidator::State
KMimeTypeValidator::validate( QString
& input
, int& ) const
68 if ( input
.isEmpty() )
71 QRegExp
acceptable( "[" ALLOWED_CHARS
"]+/[" ALLOWED_CHARS
"]+",
72 false /*case-insens.*/);
73 if ( acceptable
.exactMatch( input
) )
76 QRegExp
intermediate( "[" ALLOWED_CHARS
"]*/?[" ALLOWED_CHARS
"]*",
77 false /*case-insensitive*/);
78 if ( intermediate
.exactMatch( input
) )
84 void KMimeTypeValidator::fixup( QString
& input
) const
86 QRegExp
invalidChars("[^/" ALLOWED_CHARS
"]+");
87 input
.replace( invalidChars
, QString::null
);
90 #include "kstringvalidator.moc"