From e251c6463913bcd7c9c40b4dc168010f6de68b5a Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 5 Nov 2024 21:09:53 +0100 Subject: Check for whitespace after regex using islbrk() --- src/main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 89e3007..120a88e 100644 --- a/src/main.c +++ b/src/main.c @@ -330,14 +330,13 @@ pattern_comp(u8view_t pat) reopts |= PCRE2_UCP; for (;;) { - if (ucsgnext(&g, &pat) == 0) + if (ucsgnext(&g, &pat) == 0 || islbrk(g)) break; - if (g.len != 1) - goto bad_flag; - if (uprop_is_pat_ws(*g.p)) + int w = ucsnext(&ch, &g); + if (uprop_is_pat_ws(ch)) break; - switch (*g.p) { + switch (ch) { case 'i': reopts |= PCRE2_CASELESS; break; case 'I': reopts &= ~PCRE2_CASELESS; break; case 'l': reopts |= PCRE2_LITERAL; break; @@ -345,7 +344,7 @@ pattern_comp(u8view_t pat) case 'u': reopts |= PCRE2_UCP; break; case 'U': reopts &= ~PCRE2_UCP; break; default: - bad_flag: + VSHFT(&g, -w); cerr(EXIT_FATAL, "Unknown regex flag %s%.*s%s", lquot, SV_PRI_ARGS(g), rquot); } -- cgit v1.2.3