Vidalia 0.2.12

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 ** \brief Validates that a server nickname contains only valid characters
00014 */
00015 
00016 #include "NicknameValidator.h"
00017 #include "stringutil.h"
00018 
00019 /** Set of characters that are valid in a server's nickname. */
00020 #define VALID_NICKNAME_CHARS \
00021   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
00022  
00023 
00024 /** Constructor. */
00025 NicknameValidator::NicknameValidator(QObject *parent)
00026   : QValidator(parent)
00027 {
00028 }
00029 
00030 /** Validates the given input contains only valid nickname characters starting
00031  * at the specified position. */
00032 QValidator::State
00033 NicknameValidator::validate(QString &input, int &pos) const
00034 {
00035   Q_UNUSED(pos);
00036 
00037   /* Make sure the input only contains valid characters. If any characters
00038    * were removed, then we know the input contained invalid characters. */
00039   QString validString = ensure_valid_chars(input, VALID_NICKNAME_CHARS);
00040   return (validString.length() == input.length() ? QValidator::Acceptable
00041                                                  : QValidator::Invalid);
00042 }
00043