00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file nicknamevalidator.cpp 00024 * \version $Id: nicknamevalidator.cpp 1563 2006-12-26 06:06:04Z edmanm $ 00025 * \brief Validates that a server nickname contains only valid characters 00026 */ 00027 00028 #include <util/string.h> 00029 #include "nicknamevalidator.h" 00030 00031 /** Set of characters that are valid in a server's nickname. */ 00032 #define VALID_NICKNAME_CHARS \ 00033 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 00034 00035 00036 /** Constructor. */ 00037 NicknameValidator::NicknameValidator(QObject *parent) 00038 : QValidator(parent) 00039 { 00040 } 00041 00042 /** Validates the given input contains only valid nickname characters starting 00043 * at the specified position. */ 00044 QValidator::State 00045 NicknameValidator::validate(QString &input, int &pos) const 00046 { 00047 Q_UNUSED(pos); 00048 00049 /* Make sure the input only contains valid characters. If any characters 00050 * were removed, then we know the input contained invalid characters. */ 00051 QString validString = ensure_valid_chars(input, VALID_NICKNAME_CHARS); 00052 return (validString.length() == input.length() ? QValidator::Acceptable 00053 : QValidator::Invalid); 00054 } 00055