ASSA::Regexp Class Reference

Regexp class. More...

#include <Regexp.h>

List of all members.

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.

00018     :
00019     m_pattern (NULL),
00020     m_error_msg (new char [256]),
00021     m_compiled_pattern (new regex_t)
00022 {
00023     trace_with_mask("Regexp::Regexp", REGEXP);
00024 
00025     m_pattern = new char [pattern_.size () + 1];
00026     ::strncpy (m_pattern, pattern_.c_str (), pattern_.size ());
00027     m_pattern [pattern_.size ()] = '\0';
00028 
00029     int ret = ::regcomp (m_compiled_pattern, m_pattern, REG_EXTENDED);
00030 
00031     if (ret != 0) {
00032         ::regerror (ret, m_compiled_pattern, m_error_msg, 256);
00033         DL((REGEXP,"regcomp(\"%s\") = %d\n", m_pattern, ret));
00034         DL((REGEXP,"error: \"%s\"\n", m_error_msg));
00035 
00036         delete [] m_pattern;
00037         m_pattern = NULL;
00038     }
00039 }

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.

00043 {
00044     trace_with_mask("Regexp::~Regexp", REGEXP);
00045 
00046     if (m_pattern) {
00047         delete [] m_pattern;
00048     }
00049     if (m_error_msg) {
00050         delete [] m_error_msg;
00051     }
00052     ::regfree (m_compiled_pattern);
00053     delete (m_compiled_pattern);
00054 }


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.

00064 { 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.

00068 { 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.

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().

00059 {
00060     trace_with_mask("Regexp::match", REGEXP);
00061 
00062     if (text_ == NULL || m_pattern == NULL) {
00063         return -1;
00064     }
00065 
00070     int ret = ::regexec (m_compiled_pattern, text_, 0, NULL, 0);
00071 
00072     if (ret != 0) {
00073         ::regerror (ret, m_compiled_pattern, m_error_msg, 256);
00074         DL((REGEXP,"regexec(\"%s\") = %d\n", text_, ret));
00075         DL((REGEXP,"pattern: \"%s\"\n", m_pattern));
00076         DL((REGEXP,"error: \"%s\"\n", m_error_msg));
00077     }
00078 
00079     return (ret == 0 ? 0 : -1);
00080 }


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:
Generated on Sun Aug 13 15:08:21 2006 for libassa by  doxygen 1.4.6