nicknamevalidator.cpp

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file nicknamevalidator.cpp
00013 ** \version $Id: nicknamevalidator.cpp 2362 2008-02-29 04:30:11Z edmanm $
00014 ** \brief Validates that a server nickname contains only valid characters
00015 */
00016 
00017 #include <stringutil.h>
00018 #include "nicknamevalidator.h"
00019 
00020 /** Set of characters that are valid in a server's nickname. */
00021 #define VALID_NICKNAME_CHARS \
00022   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
00023  
00024 
00025 /** Constructor. */
00026 NicknameValidator::NicknameValidator(QObject *parent)
00027 : QValidator(parent)
00028 {
00029 }
00030 
00031 /** Validates the given input contains only valid nickname characters starting
00032  * at the specified position. */
00033 QValidator::State
00034 NicknameValidator::validate(QString &input, int &pos) const
00035 {
00036   Q_UNUSED(pos);
00037 
00038   /* Make sure the input only contains valid characters. If any characters
00039    * were removed, then we know the input contained invalid characters. */
00040   QString validString = ensure_valid_chars(input, VALID_NICKNAME_CHARS);
00041   return (validString.length() == input.length() ? QValidator::Acceptable
00042                                                  : QValidator::Invalid);
00043 }
00044 

Generated on Tue Jul 7 16:58:11 2009 for Vidalia by  doxygen 1.4.7