Vidalia
0.2.15
|
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.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file IpValidator.cpp 00013 ** \brief Validates an entered IP address 00014 */ 00015 00016 #include "IpValidator.h" 00017 00018 /** Regular expression to validate that input is a valid IP address. */ 00019 #define IP_REGEXP "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"\ 00020 "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"\ 00021 "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"\ 00022 "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b" 00023 00024 #define MATCH_ALL "*" /**< Match all IP addresses. */ 00025 00026 00027 /** Constructor. */ 00028 IpValidator::IpValidator(QObject *parent) 00029 : QRegExpValidator(QRegExp(IP_REGEXP), parent) 00030 { 00031 } 00032 00033 /** Validates the given input is either a valid IP or a "*". */ 00034 QValidator::State 00035 IpValidator::validate(QString &input, int &pos) const 00036 { 00037 if (input == MATCH_ALL) { 00038 return QValidator::Acceptable; 00039 } 00040 return QRegExpValidator::validate(input, pos); 00041 } 00042 00043 /** Validates the given input from position 0. */ 00044 QValidator::State 00045 IpValidator::validate(QString &input) const 00046 { 00047 int discard = 0; 00048 return validate(input, discard); 00049 } 00050