diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-06-26 23:14:44 +0200 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-06-26 23:14:44 +0200 |
| commit | eb1fcdf5d1058f4fbdf3a2661573dd7e4d3976f3 (patch) | |
| tree | cdb7caf92fd29cb3d2ab3d28f2cd5c9604c0d1c4 /regcomp.c | |
| parent | 16cf84d794bfe9fdb245d38760256286384d8380 (diff) | |
| download | terex-eb1fcdf5d1058f4fbdf3a2661573dd7e4d3976f3.tar.gz | |
allow raw (ASCII) matching via REG_RAW flag, so we no longer need a compile-time flag
You no longer need to build two libraries just for supporting raw/ASCII and UTF-8
patterns.
This makes using the library a lot easier and reduces the total binary size.
Since strings are always `unsigned char *` now internally and the raw vs. UTF-8
decision is important only in a few select places, it would make no sense to
use meta-programming techniques.
The test suite has been extended and is now fixed for cases with embedded
non-printable characters.
Diffstat (limited to 'regcomp.c')
| -rw-r--r-- | regcomp.c | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -181,6 +181,7 @@ static struct cvec *cclass(struct vars *, const chr *, const chr *, int); static struct cvec *allcases(struct vars *, pchr); static int cmp(const chr *, const chr *, size_t); static int casecmp(const chr *, const chr *, size_t); +static int casecmp_raw(const chr *, const chr *, size_t); /* automatically gathered by fwd; do not hand-edit */ /* =====^!^===== end forwards =====^!^===== */ @@ -231,11 +232,15 @@ struct vars { #define NOTE(b) (v->re->re_info |= (b)) /* note visible condition */ #define EMPTYARC(x, y) newarc(v->nfa, EMPTY, 0, x, y) -#ifdef REGEX_UTF8 -#define DECODECHR(buf, c) wctomb((char *)buf, c) -#else -#define DECODECHR(buf, c) ((buf)[0] = (c), 1) -#endif +static inline size_t +decodechr(struct vars *v, chr *buf, pchr c) +{ + if (v->cflags & REG_RAW) { + buf[0] = c; + return 1; + } + return wctomb((char *)buf, c); +} /* token type codes, some also used as NFA arc types */ #define EMPTY 'n' /* no token present */ @@ -445,7 +450,11 @@ compile( g->tree = v->tree; v->tree = NULL; g->ntree = v->ntree; - g->compare = (v->cflags®_ICASE) ? casecmp : cmp; + if (!(v->cflags & REG_ICASE)) { + g->compare = cmp; + } else { + g->compare = (v->cflags & REG_RAW) ? casecmp_raw : casecmp; + } g->lacons = v->lacons; v->lacons = NULL; g->nlacons = v->nlacons; @@ -1491,7 +1500,7 @@ brackpart( onechr(v, c, lp, rp); return; } - buf_len = DECODECHR(buf, c); + buf_len = decodechr(v, buf, c); startc = element(v, buf, buf+buf_len); NOERR(); break; @@ -1536,7 +1545,7 @@ brackpart( switch (v->nexttype) { case PLAIN: case RANGE: - buf_len = DECODECHR(buf, v->nextvalue); + buf_len = decodechr(v, buf, v->nextvalue); NEXT(); endc = element(v, buf, buf+buf_len); NOERR(); |
