diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /kdeui/kstringvalidator.cpp | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdeui/kstringvalidator.cpp')
-rw-r--r-- | kdeui/kstringvalidator.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/kdeui/kstringvalidator.cpp b/kdeui/kstringvalidator.cpp new file mode 100644 index 000000000..e45e0dcbe --- /dev/null +++ b/kdeui/kstringvalidator.cpp @@ -0,0 +1,90 @@ +/* + kstringvalidator.cpp + + Copyright (c) 2001 Marc Mutz <mutz@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; version 2.0 + of the License. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA +*/ + +#include "kstringvalidator.h" +#include "kdebug.h" + +// +// KStringListValidator +// + +QValidator::State KStringListValidator::validate( QString & input, int& ) const { + if ( input.isEmpty() ) return Intermediate; + + if ( isRejecting() ) // anything not in mStringList is acceptable: + if ( mStringList.find( input ) == mStringList.end() ) + return Acceptable; + else + return Intermediate; + else // only what is in mStringList is acceptable: + if ( mStringList.find( input ) != mStringList.end() ) + return Acceptable; + else + for ( QStringList::ConstIterator it = mStringList.begin() ; + it != mStringList.end() ; ++it ) + if ( (*it).startsWith( input ) || input.startsWith( *it ) ) + return Intermediate; + + return Invalid; +} + +void KStringListValidator::fixup( QString & /* input */ ) const { + if ( !isFixupEnabled() ) return; + // warn (but only once!) about non-implemented fixup(): + static bool warn = true; + if ( warn ) { + kdDebug() << "KStringListValidator::fixup() isn't yet implemented!" + << endl; + warn = false; + } +} + +// +// KMimeTypeValidator +// + +#define ALLOWED_CHARS "!#-'*+.0-9^-~+-" + +QValidator::State KMimeTypeValidator::validate( QString & input, int& ) const +{ + if ( input.isEmpty() ) + return Intermediate; + + QRegExp acceptable( "[" ALLOWED_CHARS "]+/[" ALLOWED_CHARS "]+", + false /*case-insens.*/); + if ( acceptable.exactMatch( input ) ) + return Acceptable; + + QRegExp intermediate( "[" ALLOWED_CHARS "]*/?[" ALLOWED_CHARS "]*", + false /*case-insensitive*/); + if ( intermediate.exactMatch( input ) ) + return Intermediate; + + return Invalid; +} + +void KMimeTypeValidator::fixup( QString & input ) const +{ + QRegExp invalidChars("[^/" ALLOWED_CHARS "]+"); + input.replace( invalidChars, QString::null); +} + +#include "kstringvalidator.moc" |