• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kdeui

kstringvalidator.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301 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, QString::null);
00088 }
00089 
00090 #include "kstringvalidator.moc"

kdeui

Skip menu "kdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal