Back to index

nux  3.0.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
nux::Validator Class Reference

#include <Validator.h>

Inheritance diagram for nux::Validator:
Inheritance graph
[legend]
Collaboration diagram for nux::Validator:
Collaboration graph
[legend]

List of all members.

Public Types

enum  State { Invalid = 0, Intermediate, Acceptable }

Public Member Functions

 Validator ()
virtual ~Validator ()
virtual ValidatorClone () const =0
virtual Validator::State Validate (const char *str) const
virtual void Alternative (const char *str)

Protected Member Functions

bool InitRegExp ()

Protected Attributes

NString _regexp_str
pcre * _regexp

Detailed Description

Definition at line 35 of file Validator.h.


Member Enumeration Documentation

Enumerator:
Invalid 
Intermediate 
Acceptable 

Definition at line 38 of file Validator.h.


Constructor & Destructor Documentation

Definition at line 29 of file Validator.cpp.

  {
  }

Definition at line 33 of file Validator.cpp.

  {

  }

Member Function Documentation

virtual void nux::Validator::Alternative ( const char *  str) [inline, virtual]

Reimplemented in nux::DoubleValidator, nux::HexRegExpValidator, and nux::IntegerValidator.

Definition at line 51 of file Validator.h.

{}
virtual Validator* nux::Validator::Clone ( ) const [pure virtual]

Implemented in nux::DoubleValidator, nux::HexRegExpValidator, and nux::IntegerValidator.

Here is the caller graph for this function:

bool nux::Validator::InitRegExp ( ) [protected]

Definition at line 38 of file Validator.cpp.

  {
#if defined(NUX_OS_WINDOWS)
    regex_ = _regexp_str.GetTCharPtr();
    return true;
#else
    const char *error;
    int   erroffset;
    _regexp = pcre_compile(
      _regexp_str.GetTCharPtr(),    /* the pattern */
      PCRE_MULTILINE,
      &error,         /* for error message */
      &erroffset,     /* for error offset */
      0);             /* use default character tables */

    if (!_regexp)
    {
      nuxDebugMsg("[IntegerValidator::IntegerValidator] Invalid regular expression: %s", _regexp_str.GetTCharPtr());
      return false;
    }    
    return true;
#endif
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Validator::State nux::Validator::Validate ( const char *  str) const [virtual]

Definition at line 62 of file Validator.cpp.

  {
#if defined(NUX_OS_WINDOWS)
    if (str == NULL)
      return Validator::Invalid;
    std::string search_string = str;

    if (std::regex_match(search_string.begin(), search_string.end(), regex_))
    {
      return Validator::Acceptable;
    }
    return Validator::Acceptable;
#else
    if (_regexp == 0)
      return Validator::Invalid;

    int out_vector [10];
    unsigned int offset = 0;
    int len = (int) strlen(str);

    // See the "PCRE DISCUSSION OF STACK USAGE" and why it maybe necessary to limit the stack usage.
    pcre_extra extra;
    extra.flags = PCRE_EXTRA_MATCH_LIMIT_RECURSION;
    extra.match_limit_recursion = 2000; 

    int rc = pcre_exec(_regexp, &extra, str, len, offset, 0, out_vector, 10);
    if (rc <= -1)
    {
      return Validator::Invalid;
    }
    return Validator::Acceptable;
#endif
  }

Here is the caller graph for this function:


Member Data Documentation

pcre* nux::Validator::_regexp [protected]

Definition at line 60 of file Validator.h.

Definition at line 55 of file Validator.h.


The documentation for this class was generated from the following files: