diff --git a/tmpl/parser.cc b/tmpl/parser.cc index 38b81bb..3d23e47 100644 --- a/tmpl/parser.cc +++ b/tmpl/parser.cc @@ -140,8 +140,8 @@ void Token::process() { } -MatchSet::MatchSet(const char * data, int * ovector, int ovec_size) - : m_data(data), m_ovector(ovector), m_ovec_size(ovec_size) +MatchSet::MatchSet(pcre * re, const char * data, int * ovector, int ovec_size) + : m_re(re), m_data(data), m_ovector(ovector), m_ovec_size(ovec_size) { } @@ -161,7 +161,15 @@ std::string MatchSet::operator[](int index) std::string MatchSet::operator[](const std::string & index) { - /* FIXME */ + int idx = pcre_get_stringnumber(m_re, index.c_str()); + if (idx > 0 && idx < (m_ovec_size / 3)) + { + if (m_ovector[idx] >= 0 && m_ovector[idx + 1] >= 0) + { + return string(m_data, m_ovector[idx], + m_ovector[idx + 1] - m_ovector[idx]); + } + } return ""; } diff --git a/tmpl/parser.h b/tmpl/parser.h index 6118daf..0cec6f6 100644 --- a/tmpl/parser.h +++ b/tmpl/parser.h @@ -2,6 +2,8 @@ #ifndef IMBECILE_PARSER_HEADER #define IMBECILE_PARSER_HEADER +#include + #include #include #include @@ -124,11 +126,12 @@ class I_CLASSNAME class MatchSet { public: - MatchSet(const char * data, int * ovector, int ovec_size); + MatchSet(pcre * re, const char * data, int * ovector, int ovec_size); std::string operator[](int index); std::string operator[](const std::string & index); protected: + pcre * m_re; const char * m_data; int * m_ovector; int m_ovec_size;