libassa  3.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Attributes | List of all members
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 ( const std::string &  pattern_)

Constructor.

Parameters
pattern_Regular expression pattern

Definition at line 17 of file Regexp.cpp.

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

:
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;
}
}
Regexp::~Regexp ( )

Destructor.

Release all allocated resources.

Definition at line 42 of file Regexp.cpp.

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

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

Member Function Documentation

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

Return error message.

Definition at line 64 of file Regexp.h.

References m_error_msg.

{ return m_error_msg; }
const char* ASSA::Regexp::get_pattern ( ) const
inline

Return the original pattern (uncompiled)

Definition at line 68 of file Regexp.h.

References m_pattern.

{ return m_pattern; }
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 58 of file Regexp.cpp.

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

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

{
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);
}

Member Data Documentation

regex_t* ASSA::Regexp::m_compiled_pattern
private

Definition at line 73 of file Regexp.h.

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

char* ASSA::Regexp::m_error_msg
private

Definition at line 72 of file Regexp.h.

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

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: