libassa 3.5.1
Loading...
Searching...
No Matches
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 charget_error () const
 Return error message.
 
const charget_pattern () const
 Return the original pattern (uncompiled)
 

Private Attributes

charm_pattern
 
charm_error_msg
 
regex_tm_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.

18 :
20 m_error_msg (new char [256]),
22{
23 trace_with_mask("Regexp::Regexp", REGEXP);
24
25 m_pattern = new char [pattern_.size () + 1];
26 ::strncpy (m_pattern, pattern_.c_str (), pattern_.size ());
27 m_pattern [pattern_.size ()] = '\0';
28
30
31 if (ret != 0) {
33 DL((REGEXP,"regcomp(\"%s\") = %d\n", m_pattern, ret));
34 DL((REGEXP,"error: \"%s\"\n", m_error_msg));
35
36 delete [] m_pattern;
38 }
39}
#define DL(X)
A macro for writing debug message to the Logger.
Definition Logger.h:273
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
char * m_error_msg
Definition Regexp.h:72
char * m_pattern
Definition Regexp.h:71
regex_t * m_compiled_pattern
Definition Regexp.h:73
@ 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.

43{
44 trace_with_mask("Regexp::~Regexp", REGEXP);
45
46 if (m_pattern) {
47 delete [] m_pattern;
48 }
49 if (m_error_msg) {
50 delete [] m_error_msg;
51 }
53 delete (m_compiled_pattern);
54}

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.

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

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

59{
60 trace_with_mask("Regexp::match", REGEXP);
61
62 if (text_ == NULL || m_pattern == NULL) {
63 return -1;
64 }
65
71
72 if (ret != 0) {
74 DL((REGEXP,"regexec(\"%s\") = %d\n", text_, ret));
75 DL((REGEXP,"pattern: \"%s\"\n", m_pattern));
76 DL((REGEXP,"error: \"%s\"\n", m_error_msg));
77 }
78
79 return (ret == 0 ? 0 : -1);
80}

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: