ipvalidator.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 ipvalidator.cpp
00013 ** \version $Id: ipvalidator.cpp 2362 2008-02-29 04:30:11Z edmanm $
00014 ** \brief Validates an entered IP address
00015 */
00016 
00017 #include "ipvalidator.h"
00018 
00019 /** Regular expression to validate that input is a valid IP address. */
00020 #define IP_REGEXP "\\b(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]?)"\
00023                   "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"
00024 
00025 #define MATCH_ALL "*" /**< Match all IP addresses. */
00026 
00027 
00028 /** Constructor. */
00029 IPValidator::IPValidator(QObject *parent)
00030 : QRegExpValidator(QRegExp(IP_REGEXP), parent)
00031 {
00032 }
00033 
00034 /** Validates the given input is either a valid IP or a "*". */
00035 QValidator::State
00036 IPValidator::validate(QString &input, int &pos) const
00037 {
00038   if (input == MATCH_ALL) {
00039     return QValidator::Acceptable;
00040   }
00041   return QRegExpValidator::validate(input, pos);
00042 }
00043 
00044 /** Validates the given input from position 0. */
00045 QValidator::State
00046 IPValidator::validate(QString &input) const
00047 {
00048   int discard = 0;
00049   return validate(input, discard);
00050 }
00051 

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