|
libassa 3.5.0
|
#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 |
| Regexp::Regexp | ( | const std::string & | pattern_ | ) |
Constructor.
| 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);
delete (m_compiled_pattern);
}
| 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] |
| int Regexp::match | ( | const char * | text_ | ) |
Match an ASCII character string agains the pattern this class wraps.
| text_ | Input text to match against the pattern. |
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);
}
regex_t* ASSA::Regexp::m_compiled_pattern [private] |
char* ASSA::Regexp::m_error_msg [private] |
char* ASSA::Regexp::m_pattern [private] |
1.7.3