subtraction of already painted area: be fool and
[kdelibs.git] / kdeui / kstringvalidator.cpp
blob674f0ee7db070bca63447df586fab139960badcb
1 /*
2 kstringvalidator.cpp
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
9 of the License.
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
19 02110-1301 USA
22 #include "kstringvalidator.h"
23 #include "kdebug.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() )
34 return Acceptable;
35 else
36 return Intermediate;
37 else // only what is in mStringList is acceptable:
38 if ( mStringList.find( input ) != mStringList.end() )
39 return Acceptable;
40 else
41 for ( QStringList::ConstIterator it = mStringList.begin() ;
42 it != mStringList.end() ; ++it )
43 if ( (*it).startsWith( input ) || input.startsWith( *it ) )
44 return Intermediate;
46 return Invalid;
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;
53 if ( warn ) {
54 kdDebug() << "KStringListValidator::fixup() isn't yet implemented!"
55 << endl;
56 warn = false;
61 // KMimeTypeValidator
64 #define ALLOWED_CHARS "!#-'*+.0-9^-~+-"
66 QValidator::State KMimeTypeValidator::validate( QString & input, int& ) const
68 if ( input.isEmpty() )
69 return Intermediate;
71 QRegExp acceptable( "[" ALLOWED_CHARS "]+/[" ALLOWED_CHARS "]+",
72 false /*case-insens.*/);
73 if ( acceptable.exactMatch( input ) )
74 return Acceptable;
76 QRegExp intermediate( "[" ALLOWED_CHARS "]*/?[" ALLOWED_CHARS "]*",
77 false /*case-insensitive*/);
78 if ( intermediate.exactMatch( input ) )
79 return Intermediate;
81 return Invalid;
84 void KMimeTypeValidator::fixup( QString & input ) const
86 QRegExp invalidChars("[^/" ALLOWED_CHARS "]+");
87 input.replace( invalidChars, QString::null);
90 #include "kstringvalidator.moc"