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 /regc_lex.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 'regc_lex.c')
| -rw-r--r-- | regc_lex.c | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -47,15 +47,15 @@ #define LASTTYPE(t) (v->lasttype == (t)) /* return and skip the next (unicode) character */ -#ifdef REGEX_UTF8 -#define SKIPCHR(x) do { \ - wchar_t __c; \ - v->now += mbtowc(&__c, (const char *)v->now, v->stop - v->now); \ - x = __c; \ -} while (0) -#else -#define SKIPCHR(x) do x = *v->now++; while (0) -#endif +static inline pchr +skipchr(struct vars *v) +{ + if (v->cflags & REG_RAW) + return *v->now++; + wchar_t c; + v->now += mbtowc(&c, (const char *)v->now, v->stop - v->now); + return c; +} /* lexical contexts */ #define L_ERE 1 /* mainline ERE/ARE */ @@ -383,7 +383,7 @@ next( * Okay, time to actually get a character. */ - SKIPCHR(c); + c = skipchr(v); /* * Deal with the easy contexts, punt EREs to code below. @@ -709,7 +709,7 @@ next( assert(!ATEOS()); if (!(v->cflags®_ADVF)) {/* only AREs have non-trivial escapes */ - SKIPCHR(c); + c = skipchr(v); if (iscalnum(c)) { NOTE(REG_UBSALNUM); NOTE(REG_UUNSPEC); @@ -766,7 +766,7 @@ lexescape( assert(v->cflags®_ADVF); assert(!ATEOS()); - SKIPCHR(c); + c = skipchr(v); if (!iscalnum(c)) { RETV(PLAIN, c); } @@ -790,7 +790,7 @@ lexescape( if (ATEOS()) { FAILW(REG_EESCAPE); } - SKIPCHR(c); + c = skipchr(v); RETV(PLAIN, c & 037); break; case CHR('d'): @@ -1055,7 +1055,7 @@ brenext( FAILW(REG_EESCAPE); } - SKIPCHR(c); + c = skipchr(v); switch (c) { case CHR('{'): INTOCON(L_BBND); |
