Loading...
Searching...
No Matches
ASSA::Regexp Class Reference

Regexp class. More...

`#include <Regexp.h>`

## Public Member Functions

| Regexp (const std::string &pattern_)
| Constructor.
| ~Regexp ()
| Destructor.
int | match (const char *text_)
| Match an ASCII character string agains the pattern this class wraps.
const char * | get_error () const
| Return error message.
const char * | get_pattern () const
| Return the original pattern (uncompiled)

## Private Attributes

char * | m_pattern
char * | m_error_msg
regex_t * | m_compiled_pattern

## Detailed Description

Regexp class.

Class Regexp wraps regexp structure and associated library functions.

Definition at line 43 of file Regexp.h.

## Constructor & Destructor Documentation

## Regexp()

Regexp::Regexp | ( | const std::string & | pattern_ | ) |

Constructor.

Parameters

  pattern_ | Regular expression pattern

Definition at line 16 of file Regexp.cpp.

:
m_pattern (NULL),
m_error_msg (new char [256]),
m_compiled_pattern (new regex_t)
{
trace_with_mask("Regexp::Regexp", REGEXP);
m_pattern = new char [pattern_.size () + 1];
::strncpy (m_pattern, pattern_.c_str (), pattern_.size ());
m_pattern [pattern_.size ()] = '\0';
int ret = ::regcomp (m_compiled_pattern, m_pattern, REG_EXTENDED);
if (ret != 0) {
::regerror (ret, m_compiled_pattern, m_error_msg, 256);
DL((REGEXP,"regcomp(\"%s\") = %d\n", m_pattern, ret));
DL((REGEXP,"error: \"%s\"\n", m_error_msg));
delete [] m_pattern;
m_pattern = NULL;
}
}
DL
#define DL(X)
A macro for writing debug message to the Logger.
Definition Logger.h:273
trace_with_mask
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
ASSA::AutoPtrRef
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
ASSA::Regexp::m_error_msg
char * m_error_msg
Definition Regexp.h:72
ASSA::Regexp::m_pattern
char * m_pattern
Definition Regexp.h:71
ASSA::Regexp::m_compiled_pattern
regex_t * m_compiled_pattern
Definition Regexp.h:73
ASSA::REGEXP
@ REGEXP
Class RegExp messages
Definition LogMask.h:53

References DL, m_compiled_pattern, m_error_msg, m_pattern, ASSA::REGEXP, and trace_with_mask.

## ~Regexp()

Regexp::~Regexp | ( |  | ) |

Destructor.

Release all allocated resources.

Definition at line 41 of file Regexp.cpp.

{
trace_with_mask("Regexp::~Regexp", REGEXP);
if (m_pattern) {
delete [] m_pattern;
}
if (m_error_msg) {
delete [] m_error_msg;
}
::regfree (m_compiled_pattern);
delete (m_compiled_pattern);
}

References m_compiled_pattern, m_error_msg, m_pattern, ASSA::REGEXP, and trace_with_mask.

## Member Function Documentation

## get_error()

const char * ASSA::Regexp::get_error | ( |  | ) | const

inline

Return error message.

Definition at line 64 of file Regexp.h.

{ return m_error_msg; }

References m_error_msg.

## get_pattern()

const char * ASSA::Regexp::get_pattern | ( |  | ) | const

inline

Return the original pattern (uncompiled)

Definition at line 68 of file Regexp.h.

{ return m_pattern; }

References m_pattern.

## match()

int Regexp::match | ( | const char * | text_ | ) |

Match an ASCII character string agains the pattern this class wraps.

Parameters

  text_ | Input text to match against the pattern.

Returns
  0 if text_ matches the pattern; -1 if not.

regexec(3) returns zero for a successful match or REG_NOMATCH for failure.

Definition at line 57 of file Regexp.cpp.

{
trace_with_mask("Regexp::match", REGEXP);
if (text_ == NULL || m_pattern == NULL) {
return -1;
}
int ret = ::regexec (m_compiled_pattern, text_, 0, NULL, 0);
if (ret != 0) {
::regerror (ret, m_compiled_pattern, m_error_msg, 256);
DL((REGEXP,"regexec(\"%s\") = %d\n", text_, ret));
DL((REGEXP,"pattern: \"%s\"\n", m_pattern));
DL((REGEXP,"error: \"%s\"\n", m_error_msg));
}
return (ret == 0 ? 0 : -1);
}

References DL, m_compiled_pattern, m_error_msg, m_pattern, ASSA::REGEXP, and trace_with_mask.

Referenced by ASSA::IniFile::load().

## Member Data Documentation

## m_compiled_pattern

regex_t* ASSA::Regexp::m_compiled_pattern

private

Definition at line 73 of file Regexp.h.

Referenced by match(), Regexp(), and ~Regexp().

## m_error_msg

char* ASSA::Regexp::m_error_msg

private

Definition at line 72 of file Regexp.h.

Referenced by get_error(), match(), Regexp(), and ~Regexp().

## m_pattern

char* ASSA::Regexp::m_pattern

private

Definition at line 71 of file Regexp.h.

Referenced by get_pattern(), match(), Regexp(), and ~Regexp().

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

- Regexp.h
- Regexp.cpp