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

kdeui

  • kdeui
kstringvalidator.cpp
1 /*
2  kstringvalidator.cpp
3 
4  Copyright (c) 2001 Marc Mutz <mutz@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; version 2.0
9  of the License.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public
17  License along with this library; if not, write to the Free
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301 USA
20 */
21 
22 #include "kstringvalidator.h"
23 #include "kdebug.h"
24 
25 //
26 // KStringListValidator
27 //
28 
29 TQValidator::State KStringListValidator::validate( TQString & input, int& ) const {
30  if ( input.isEmpty() ) return Intermediate;
31 
32  if ( isRejecting() ) // anything not in mStringList is acceptable:
33  if ( mStringList.find( input ) == mStringList.end() )
34  return Acceptable;
35  else
36  return Intermediate;
37  else // only what is in mStringList is acceptable:
38  if ( mStringList.find( input ) != mStringList.end() )
39  return Acceptable;
40  else
41  for ( TQStringList::ConstIterator it = mStringList.begin() ;
42  it != mStringList.end() ; ++it )
43  if ( (*it).startsWith( input ) || input.startsWith( *it ) )
44  return Intermediate;
45 
46  return Invalid;
47 }
48 
49 void KStringListValidator::fixup( TQString & /* input */ ) const {
50  if ( !isFixupEnabled() ) return;
51  // warn (but only once!) about non-implemented fixup():
52  static bool warn = true;
53  if ( warn ) {
54  kdDebug() << "KStringListValidator::fixup() isn't yet implemented!"
55  << endl;
56  warn = false;
57  }
58 }
59 
60 //
61 // KMimeTypeValidator
62 //
63 
64 #define ALLOWED_CHARS "!#-'*+.0-9^-~+-"
65 
66 TQValidator::State KMimeTypeValidator::validate( TQString & input, int& ) const
67 {
68  if ( input.isEmpty() )
69  return Intermediate;
70 
71  TQRegExp acceptable( "[" ALLOWED_CHARS "]+/[" ALLOWED_CHARS "]+",
72  false /*case-insens.*/);
73  if ( acceptable.exactMatch( input ) )
74  return Acceptable;
75 
76  TQRegExp intermediate( "[" ALLOWED_CHARS "]*/?[" ALLOWED_CHARS "]*",
77  false /*case-insensitive*/);
78  if ( intermediate.exactMatch( input ) )
79  return Intermediate;
80 
81  return Invalid;
82 }
83 
84 void KMimeTypeValidator::fixup( TQString & input ) const
85 {
86  TQRegExp invalidChars("[^/" ALLOWED_CHARS "]+");
87  input.replace( invalidChars, TQString());
88 }
89 
90 #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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |