summaryrefslogtreecommitdiff
path: root/Ivy/IvyBinding.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Ivy/IvyBinding.cxx')
-rw-r--r--Ivy/IvyBinding.cxx46
1 files changed, 17 insertions, 29 deletions
diff --git a/Ivy/IvyBinding.cxx b/Ivy/IvyBinding.cxx
index 9013cad..c365b71 100644
--- a/Ivy/IvyBinding.cxx
+++ b/Ivy/IvyBinding.cxx
@@ -24,7 +24,7 @@ static int err_offset;
#ifdef USE_PCRE
static const char *err_buf;
#else /* we don't USE_PCRE */
- static char err_buf[4096];
+static ivy::string err_buf;
#endif /* USE_PCRE */
/* classes de messages emis par l'application utilise pour le filtrage */
@@ -35,13 +35,15 @@ static IvyBinding token_extract;
IvyBinding::IvyBinding()
{
+ nb_match = 0;
#ifdef USE_PCRE
regexp = NULL;
inspect = NULL;
+
#else /* we don't USE_PCRE */
- free( regexp );
+ regexp = NULL;
#endif /* USE_PCRE */
- nb_match = 0;
+
}
IvyBinding::~IvyBinding()
{
@@ -51,7 +53,7 @@ IvyBinding::~IvyBinding()
if (regexp!=NULL)
pcre_free(regexp);
#else /* we don't USE_PCRE */
- free( regexp );
+ delete regexp;
#endif /* USE_PCRE */
}
bool IvyBinding::Compile( const char * expression, int *erroffset, const char **errmessage )
@@ -75,18 +77,16 @@ bool IvyBinding::Compile( const char * expression, int *erroffset, const char *
printf("Error compiling '%s', %s\n", expression, err_buf);
}
#else /* we don't USE_PCRE */
- regex_t regexp;
- int reg;
- reg = regcomp(&regexp, expression, REGCOMP_OPT|REG_EXTENDED);
- if ( reg == 0 )
+ regexp = new Regexp( expression, false );
+ if ( regexp->CompiledOK() )
{
- this->next = NULL;
+ compile = true;
}
else
{
- regerror (reg, &regexp, err_buf, sizeof(err_buf) );
+ err_buf = regexp->GetErrorString();
*erroffset = err_offset;
- *errmessage = err_buf;
+ *errmessage = err_buf.c_str();
printf("Error compiling '%s', %s\n", expression, err_buf);
}
#endif /* USE_PCRE */
@@ -109,15 +109,9 @@ int IvyBinding::Exec( const char * message )
OVECSIZE);
if (nb_match<1) return 0; /* no match */
#else /* we don't USE_PCRE */
- memset( match, -1, sizeof(match )); /* work around bug !!!*/
- nb_match = regexec (&regexp, message, MAX_MSG_FIELDS, match, 0)
- if (nb_match == REG_NOMATCH)
+ if ( !regexp->Match( message ) )
return 0;
- for ( index = 1; index < MAX_MSG_FIELDS; index++ )
- {
- if ( match[i].rm_so != -1 )
- nb_match++;
- }
+ nb_match = regexp->SubStrings()+1; // +1 first arg is wall string
#endif /* USE_PCRE */
return nb_match;
}
@@ -130,16 +124,10 @@ void IvyBinding::Match( const char *message, int argnum, int *arglen, const char
*arg = message + ovector[2*argnum];
#else /* we don't USE_PCRE */
- regmatch_t* p;
-
- p = &match[argnum+1];
- if ( p->rm_so != -1 ) {
- *arglen = p->rm_eo - p->rm_so;
- *arg = message + p->rm_so;
- } else { // ARG VIDE
- *arglen = 0;
- *arg = NULL;
- }
+
+ *arglen = regexp->SubLength(argnum);
+ *arg = message + regexp->SubStart(argnum);
+
#endif /* USE_PCRE */
}