Vidalia  0.3.1
IpValidator.cpp
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file IpValidator.cpp
13 ** \brief Validates an entered IP address
14 */
15 
16 #include "IpValidator.h"
17 
18 /** Regular expression to validate that input is a valid IP address. */
19 #define IP_REGEXP "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"\
20  "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"\
21  "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"\
22  "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"
23 
24 #define MATCH_ALL "*" /**< Match all IP addresses. */
25 
26 
27 /** Constructor. */
28 IpValidator::IpValidator(QObject *parent)
29 : QRegExpValidator(QRegExp(IP_REGEXP), parent)
30 {
31 }
32 
33 /** Validates the given input is either a valid IP or a "*". */
34 QValidator::State
35 IpValidator::validate(QString &input, int &pos) const
36 {
37  if (input == MATCH_ALL) {
38  return QValidator::Acceptable;
39  }
40  return QRegExpValidator::validate(input, pos);
41 }
42 
43 /** Validates the given input from position 0. */
44 QValidator::State
45 IpValidator::validate(QString &input) const
46 {
47  int discard = 0;
48  return validate(input, discard);
49 }
50 
IpValidator.h
MATCH_ALL
#define MATCH_ALL
Definition: IpValidator.cpp:24
IpValidator::validate
QValidator::State validate(QString &input) const
Definition: IpValidator.cpp:45
IP_REGEXP
#define IP_REGEXP
Definition: IpValidator.cpp:19
IpValidator::IpValidator
IpValidator(QObject *parent)
Definition: IpValidator.cpp:28