Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
Arc::RegularExpression Class Reference

A regular expression class. More...

#include <ArcRegex.h>

Collaboration diagram for Arc::RegularExpression:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RegularExpression ()
 default constructor
 RegularExpression (std::string pattern)
 Creates a reges from a pattern string.
 RegularExpression (const RegularExpression &regex)
 Copy constructor.
 ~RegularExpression ()
 Destructor.
const RegularExpressionoperator= (const RegularExpression &regex)
 Assignment operator.
bool isOk ()
 Returns true if the pattern of this regex is ok.
bool hasPattern (std::string str)
 Returns true if this regex has the pattern provided.
bool match (const std::string &str) const
 Returns true if this regex matches whole string provided.
bool match (const std::string &str, std::list< std::string > &unmatched, std::list< std::string > &matched) const
 Returns true if this regex matches the string provided. Unmatched parts of the string are stored in 'unmatched'. Matched parts of the string are stored in 'matched'.
std::string getPattern () const
 Returns patter.

Private Attributes

std::string pattern
regex_t preg
int status

Detailed Description

A regular expression class.

This class is a wrapper around the functions provided in regex.h.

Definition at line 16 of file ArcRegex.h.


Constructor & Destructor Documentation

default constructor

Definition at line 20 of file ArcRegex.h.

{}

Creates a reges from a pattern string.

Definition at line 12 of file ArcRegex.cpp.

    : pattern(pattern) {
    status = regcomp(&preg, pattern.c_str(), REG_EXTENDED);
  }

Copy constructor.

Definition at line 17 of file ArcRegex.cpp.

    : pattern(regex.pattern) {
    status = regcomp(&preg, pattern.c_str(), 0);
  }

Destructor.

Definition at line 22 of file ArcRegex.cpp.

                                        {
    regfree(&preg);
  }

Member Function Documentation

std::string Arc::RegularExpression::getPattern ( ) const

Returns patter.

Definition at line 72 of file ArcRegex.cpp.

                                                {
    return pattern;
  }
bool Arc::RegularExpression::hasPattern ( std::string  str)

Returns true if this regex has the pattern provided.

Definition at line 37 of file ArcRegex.cpp.

                                                  {
    return pattern == str;
  }

Returns true if the pattern of this regex is ok.

Definition at line 33 of file ArcRegex.cpp.

                               {
    return status == 0;
  }

Here is the caller graph for this function:

bool Arc::RegularExpression::match ( const std::string &  str) const

Returns true if this regex matches whole string provided.

Definition at line 41 of file ArcRegex.cpp.

                                                          {
    std::list<std::string> unmatched;
    std::list<std::string> matched;
    return match(str, unmatched, matched) && (unmatched.size() == 0);
  }

Here is the caller graph for this function:

bool Arc::RegularExpression::match ( const std::string &  str,
std::list< std::string > &  unmatched,
std::list< std::string > &  matched 
) const

Returns true if this regex matches the string provided. Unmatched parts of the string are stored in 'unmatched'. Matched parts of the string are stored in 'matched'.

Definition at line 47 of file ArcRegex.cpp.

                                                                                                                      {
    if (status == 0) {
      int st;
      regmatch_t rm[256];
      unmatched.clear();
      st = regexec(&preg, str.c_str(), 256, rm, 0);
      if (st != 0)
        return false;
      regoff_t p = 0;
      for (int n = 0; n < 256; ++n) {
        if (rm[n].rm_so == -1)
          break;
        matched.push_back(str.substr(rm[n].rm_so, rm[n].rm_eo - rm[n].rm_so));
        if (rm[n].rm_so > p)
          unmatched.push_back(str.substr(p, rm[n].rm_so - p));
        p = rm[n].rm_eo;
      }
      if (p < str.length())
        unmatched.push_back(str.substr(p));
      return true;
    }
    else
      return false;
  }
const RegularExpression & Arc::RegularExpression::operator= ( const RegularExpression regex)

Assignment operator.

Definition at line 26 of file ArcRegex.cpp.

                                                                                      {
    regfree(&preg);
    pattern = regex.pattern;
    status = regcomp(&preg, pattern.c_str(), 0);
    return *this;
  }

Member Data Documentation

std::string Arc::RegularExpression::pattern [private]

Definition at line 52 of file ArcRegex.h.

regex_t Arc::RegularExpression::preg [private]

Definition at line 53 of file ArcRegex.h.

Definition at line 54 of file ArcRegex.h.


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