diff options
author | Timothy Pearson <[email protected]> | 2011-11-06 15:56:40 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-06 15:56:40 -0600 |
commit | e16866e072f94410321d70daedbcb855ea878cac (patch) | |
tree | ee3f52eabde7da1a0e6ca845fb9c2813cf1558cf /tdeui/kstringvalidator.cpp | |
parent | a58c20c1a7593631a1b50213c805507ebc16adaf (diff) | |
download | tdelibs-e16866e072f94410321d70daedbcb855ea878cac.tar.gz tdelibs-e16866e072f94410321d70daedbcb855ea878cac.zip |
Actually move the kde files that were renamed in the last commit
Diffstat (limited to 'tdeui/kstringvalidator.cpp')
-rw-r--r-- | tdeui/kstringvalidator.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tdeui/kstringvalidator.cpp b/tdeui/kstringvalidator.cpp new file mode 100644 index 000000000..4c2f33890 --- /dev/null +++ b/tdeui/kstringvalidator.cpp @@ -0,0 +1,90 @@ +/* + kstringvalidator.cpp + + Copyright (c) 2001 Marc Mutz <[email protected]> + + 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 +// + +TQValidator::State KStringListValidator::validate( TQString & input, int& ) const { + if ( input.isEmpty() ) return Intermediate; + + if ( isRejecting() ) // anything not in mStringList is acceptable: + if ( mStringList.find( input ) == mStringList.end() ) + return Acceptable; + else + return Intermediate; + else // only what is in mStringList is acceptable: + if ( mStringList.find( input ) != mStringList.end() ) + return Acceptable; + else + for ( TQStringList::ConstIterator it = mStringList.begin() ; + it != mStringList.end() ; ++it ) + if ( (*it).startsWith( input ) || input.startsWith( *it ) ) + return Intermediate; + + return Invalid; +} + +void KStringListValidator::fixup( TQString & /* input */ ) const { + 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^-~+-" + +TQValidator::State KMimeTypeValidator::validate( TQString & input, int& ) const +{ + if ( input.isEmpty() ) + return Intermediate; + + TQRegExp acceptable( "[" ALLOWED_CHARS "]+/[" ALLOWED_CHARS "]+", + false /*case-insens.*/); + if ( acceptable.exactMatch( input ) ) + return Acceptable; + + TQRegExp intermediate( "[" ALLOWED_CHARS "]*/?[" ALLOWED_CHARS "]*", + false /*case-insensitive*/); + if ( intermediate.exactMatch( input ) ) + return Intermediate; + + return Invalid; +} + +void KMimeTypeValidator::fixup( TQString & input ) const +{ + TQRegExp invalidChars("[^/" ALLOWED_CHARS "]+"); + input.replace( invalidChars, TQString()); +} + +#include "kstringvalidator.moc" |