From 9a2a365d61c9cd0d93e8c30a9833b76faabe18c7 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 25 Aug 2013 10:14:39 +0300 Subject: [PATCH] added API to compile non-asciiz regular expressions --- src/libre9/re9.c | 14 ++++++++++++-- src/libre9/re9.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libre9/re9.c b/src/libre9/re9.c index f633b7d..10b976f 100644 --- a/src/libre9/re9.c +++ b/src/libre9/re9.c @@ -1197,10 +1197,15 @@ static void optimize (re9_compiler_t *ci) { } -re9_prog_t *re9_compile (const char *s, int flags, const char **errmsg) { +re9_prog_t *re9_compile_ex (const char *s, const char *eol, int flags, const char **errmsg) { int token; re9_compiler_t * volatile ci; re9_prog_t *pres; + if (s == NULL) { + if (errmsg != NULL) *errmsg = "can't parse NULL regexp"; + return NULL; + } + if (eol == NULL) eol = s+strlen(s); else if (eol < s) eol = s; if ((ci = malloc(sizeof(*ci))) == NULL) { if (errmsg != NULL) *errmsg = "out of memory"; return NULL; @@ -1229,7 +1234,7 @@ re9_prog_t *re9_compile (const char *s, int flags, const char **errmsg) { } /* go compile the sucker */ ci->expr = s; - ci->expr_eol = ci->expr+strlen(ci->expr); + ci->expr_eol = eol; ci->nbra = 0; ci->atorp = ci->atorstack; ci->andp = ci->andstack; @@ -1280,6 +1285,11 @@ re9_prog_t *re9_compile (const char *s, int flags, const char **errmsg) { } +re9_prog_t *re9_compile (const char *s, int flags, const char **errmsg) { + return re9_compile_ex(s, NULL, flags, errmsg); +} + + int re9_nsub (const re9_prog_t *p) { return (p != NULL ? p->nsub : 0); } diff --git a/src/libre9/re9.h b/src/libre9/re9.h index da49a35..3df44c9 100644 --- a/src/libre9/re9.h +++ b/src/libre9/re9.h @@ -130,6 +130,8 @@ enum { */ extern re9_prog_t *re9_compile (const char *s, int flags, const char **errmsg); +extern re9_prog_t *re9_compile_ex (const char *s, const char *eol, int flags, const char **errmsg); + /* return number of captures in this regexp; 0th capture is always full match */ extern int re9_nsub (const re9_prog_t *p); -- 2.11.4.GIT