kstringvalidator.cpp
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #include "kstringvalidator.h"
00023 #include "kdebug.h"
00024 
00025 
00026 
00027 
00028 
00029 QValidator::State KStringListValidator::validate( QString & input, int& ) const {
00030   if ( input.isEmpty() ) return Intermediate;
00031 
00032   if ( isRejecting() ) 
00033     if ( mStringList.find( input ) == mStringList.end() )
00034       return Acceptable;
00035     else
00036       return Intermediate;
00037   else 
00038     if ( mStringList.find( input ) != mStringList.end() )
00039       return Acceptable;
00040     else
00041       for ( QStringList::ConstIterator it = mStringList.begin() ;
00042         it != mStringList.end() ; ++it )
00043     if ( (*it).startsWith( input ) || input.startsWith( *it ) )
00044       return Intermediate;
00045 
00046   return Invalid;
00047 }
00048 
00049 void KStringListValidator::fixup( QString &  ) const {
00050   if ( !isFixupEnabled() ) return;
00051   
00052   static bool warn = true;
00053   if ( warn ) {
00054     kdDebug() << "KStringListValidator::fixup() isn't yet implemented!"
00055           << endl;
00056     warn = false;
00057   }
00058 }
00059 
00060 
00061 
00062 
00063 
00064 #define ALLOWED_CHARS "!#-'*+.0-9^-~+-"
00065 
00066 QValidator::State KMimeTypeValidator::validate( QString & input, int& ) const
00067 {
00068   if ( input.isEmpty() )
00069     return Intermediate;
00070 
00071   QRegExp acceptable( "[" ALLOWED_CHARS "]+/[" ALLOWED_CHARS "]+",
00072               false );
00073   if ( acceptable.exactMatch( input ) )
00074     return Acceptable;
00075 
00076   QRegExp intermediate( "[" ALLOWED_CHARS "]*/?[" ALLOWED_CHARS "]*",
00077             false );
00078   if ( intermediate.exactMatch( input ) )
00079     return Intermediate;
00080 
00081   return Invalid;
00082 }
00083 
00084 void KMimeTypeValidator::fixup( QString & input ) const
00085 {
00086   QRegExp invalidChars("[^/" ALLOWED_CHARS "]+");
00087   input.replace( invalidChars, "");
00088 }
00089 
00090 #include "kstringvalidator.moc"
 
This file is part of the documentation for kdeui Library Version 3.2.0.