#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 |
Class Regexp wraps regexp structure and associated library functions.
Definition at line 43 of file Regexp.h.
|
Constructor.
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 }
|
|
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 }
|
|
Return error message.
Definition at line 64 of file Regexp.h. References m_error_msg. 00064 { return m_error_msg; }
|
|
Return the original pattern (uncompiled).
Definition at line 68 of file Regexp.h. References m_pattern. 00068 { return m_pattern; }
|
|
Match an ASCII character string agains the pattern this class wraps.
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 }
|
|
|
|
Definition at line 72 of file Regexp.h. Referenced by get_error(), match(), Regexp(), and ~Regexp(). |
|
Definition at line 71 of file Regexp.h. Referenced by get_pattern(), match(), Regexp(), and ~Regexp(). |