• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

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., 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 TQValidator::State KStringListValidator::validate( TQString & 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 ( TQStringList::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( TQString & /* 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 TQValidator::State KMimeTypeValidator::validate( TQString & input, int& ) const
00067 {
00068   if ( input.isEmpty() )
00069     return Intermediate;
00070 
00071   TQRegExp acceptable( "[" ALLOWED_CHARS "]+/[" ALLOWED_CHARS "]+",
00072               false /*case-insens.*/);
00073   if ( acceptable.exactMatch( input ) )
00074     return Acceptable;
00075 
00076   TQRegExp 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( TQString & input ) const
00085 {
00086   TQRegExp invalidChars("[^/" ALLOWED_CHARS "]+");
00087   input.replace( invalidChars, TQString());
00088 }
00089 
00090 #include "kstringvalidator.moc"

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.7.1
This website is maintained by Timothy Pearson.