diff options
author | fcolin | 2008-12-10 11:57:07 +0000 |
---|---|---|
committer | fcolin | 2008-12-10 11:57:07 +0000 |
commit | bab8b091f69679c373e4f8ccfa794cd52419db8f (patch) | |
tree | a6fc7fc11b58ebd8ca819bbd208aa44c79e9e468 /Ivy/IvyBinding.cxx | |
parent | cccb229e246f7331ff703d4817b414c66991e55e (diff) | |
download | ivy-cplusplus-bab8b091f69679c373e4f8ccfa794cd52419db8f.zip ivy-cplusplus-bab8b091f69679c373e4f8ccfa794cd52419db8f.tar.gz ivy-cplusplus-bab8b091f69679c373e4f8ccfa794cd52419db8f.tar.bz2 ivy-cplusplus-bab8b091f69679c373e4f8ccfa794cd52419db8f.tar.xz |
mise en conformite avec Regexp.cxx et Regexp.h pour compilation sans USE_PCRE
Diffstat (limited to 'Ivy/IvyBinding.cxx')
-rw-r--r-- | Ivy/IvyBinding.cxx | 46 |
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(®exp, expression, REGCOMP_OPT|REG_EXTENDED); - if ( reg == 0 ) + regexp = new Regexp( expression, false ); + if ( regexp->CompiledOK() ) { - this->next = NULL; + compile = true; } else { - regerror (reg, ®exp, 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 (®exp, 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 */ } |