From 70846641e4fc5494df1f4d10d93d73a31276b0f6 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Sat, 21 Sep 2024 08:33:42 +1000 Subject: regexp, regsub: add support for -expanded Fixes #311 Signed-off-by: Steve Bennett --- jimregexp.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'jimregexp.c') diff --git a/jimregexp.c b/jimregexp.c index 136b0c0..38db210 100644 --- a/jimregexp.c +++ b/jimregexp.c @@ -948,6 +948,27 @@ cc_switch: ret = regnode(preg, EXACTLY); + if (preg->cflags & REG_EXPANDED) { + /* Skip leading white space */ + while ((ch = *preg->regparse) != 0) { + if (strchr(" \t\r\n\f\v", ch)) { + preg->regparse++; + continue; + } + break; + } + if (ch == '#') { + /* And skip comments to end of line */ + preg->regparse++; + while ((ch = *preg->regparse) != 0) { + preg->regparse++; + if (ch == '\n') { + break; + } + } + } + } + /* Note that a META operator such as ? or * consumes the * preceding char. * Thus we must be careful to look ahead by 2 and add the @@ -993,6 +1014,12 @@ cc_switch: break; } + /* For REG_EXPANDED, if we hit white space, stop */ + if ((preg->cflags & REG_EXPANDED) && n == 1 && strchr(" \t\r\n\f\v", ch)) { + preg->regparse += n; + break; + } + /* No, so just add this char normally */ regc(preg, ch); added++; -- cgit v1.1