kstringvalidator.cpp Source File (kdeui Library)

| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kstringvalidator.cpp

    00001 /*
    00002     kstringvalidator.cpp
    00003
    00004     Copyright (c) 2001 Marc Mutz <mutz@kde.org>
    00005
    00006     This library is free software; you can redistribute it and/or
    00007     modify it under the terms of the GNU Library General Public
    00008     License as published by the Free Software Foundation; version 2.0
    00009     of the License.
    00010
    00011     This library is distributed in the hope that it will be useful,
    00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014     Library General Public License for more details.
    00015
    00016     You should have received a copy of the GNU Library General Public
    00017     License along with this library; if not, write to the Free
    00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    00019     02111-1307 USA
    00020 */
    00021
    00022 #include "kstringvalidator.h"
    00023 #include "kdebug.h"
    00024
    00025 //
    00026 // KStringListValidator
    00027 //
    00028
    00029 QValidator::State KStringListValidator::validate( QString & input, int& ) const {
    00030   if ( input.isEmpty() ) return Intermediate;
    00031
    00032   if ( isRejecting() ) // anything not in mStringList is acceptable:
    00033     if ( mStringList.find( input ) == mStringList.end() )
    00034       return Acceptable;
    00035     else
    00036       return Intermediate;
    00037   else // only what is in mStringList is acceptable:
    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 & /* input */ ) const {
    00050   if ( !isFixupEnabled() ) return;
    00051   // warn (but only once!) about non-implemented fixup():
    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 // KMimeTypeValidator
    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 /*case-insens.*/);
    00073   if ( acceptable.exactMatch( input ) )
    00074     return Acceptable;
    00075
    00076   QRegExp intermediate( "[" ALLOWED_CHARS "]*/?[" ALLOWED_CHARS "]*",
    00077                         false /*case-insensitive*/);
    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 kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:57:45 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001