You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.5 KiB
91 lines
2.5 KiB
15 years ago
|
/*
|
||
|
kstringvalidator.cpp
|
||
|
|
||
|
Copyright (c) 2001 Marc Mutz <mutz@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; version 2.0
|
||
|
of the License.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public
|
||
|
License along with this library; if not, write to the Free
|
||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||
|
02110-1301 USA
|
||
|
*/
|
||
|
|
||
|
#include "kstringvalidator.h"
|
||
|
#include "kdebug.h"
|
||
|
|
||
|
//
|
||
|
// KStringListValidator
|
||
|
//
|
||
|
|
||
15 years ago
|
TQValidator::State KStringListValidator::validate( TQString & input, int& ) const {
|
||
15 years ago
|
if ( input.isEmpty() ) return Intermediate;
|
||
|
|
||
|
if ( isRejecting() ) // anything not in mStringList is acceptable:
|
||
13 years ago
|
if ( mStringList.find( input ) == mStringList.end() )
|
||
15 years ago
|
return Acceptable;
|
||
|
else
|
||
|
return Intermediate;
|
||
|
else // only what is in mStringList is acceptable:
|
||
13 years ago
|
if ( mStringList.find( input ) != mStringList.end() )
|
||
15 years ago
|
return Acceptable;
|
||
|
else
|
||
15 years ago
|
for ( TQStringList::ConstIterator it = mStringList.begin() ;
|
||
15 years ago
|
it != mStringList.end() ; ++it )
|
||
|
if ( (*it).startsWith( input ) || input.startsWith( *it ) )
|
||
|
return Intermediate;
|
||
|
|
||
|
return Invalid;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KStringListValidator::fixup( TQString & /* input */ ) const {
|
||
15 years ago
|
if ( !isFixupEnabled() ) return;
|
||
|
// warn (but only once!) about non-implemented fixup():
|
||
|
static bool warn = true;
|
||
|
if ( warn ) {
|
||
|
kdDebug() << "KStringListValidator::fixup() isn't yet implemented!"
|
||
|
<< endl;
|
||
|
warn = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// KMimeTypeValidator
|
||
|
//
|
||
|
|
||
|
#define ALLOWED_CHARS "!#-'*+.0-9^-~+-"
|
||
|
|
||
15 years ago
|
TQValidator::State KMimeTypeValidator::validate( TQString & input, int& ) const
|
||
15 years ago
|
{
|
||
|
if ( input.isEmpty() )
|
||
|
return Intermediate;
|
||
|
|
||
15 years ago
|
TQRegExp acceptable( "[" ALLOWED_CHARS "]+/[" ALLOWED_CHARS "]+",
|
||
15 years ago
|
false /*case-insens.*/);
|
||
|
if ( acceptable.exactMatch( input ) )
|
||
|
return Acceptable;
|
||
|
|
||
15 years ago
|
TQRegExp intermediate( "[" ALLOWED_CHARS "]*/?[" ALLOWED_CHARS "]*",
|
||
15 years ago
|
false /*case-insensitive*/);
|
||
|
if ( intermediate.exactMatch( input ) )
|
||
|
return Intermediate;
|
||
|
|
||
|
return Invalid;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KMimeTypeValidator::fixup( TQString & input ) const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQRegExp invalidChars("[^/" ALLOWED_CHARS "]+");
|
||
13 years ago
|
input.replace( invalidChars, TQString());
|
||
15 years ago
|
}
|
||
|
|
||
|
#include "kstringvalidator.moc"
|