From ec5976bbd5a930e040a34b9e93bf9cc41d7230c1 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 1 Nov 2024 20:26:48 +0100 Subject: Simplify check for empty regex --- src/main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index d5bbedf..f702842 100644 --- a/src/main.c +++ b/src/main.c @@ -277,19 +277,15 @@ pattern_comp(u8view_t pat) /* Find the right delimeter, which is optional for the last operator */ - u8view_t re = {pat.p, -1}; + u8view_t re = {pat.p, 0}; while ((w = ucsnext(&ch, &pat)) != 0) { if (ch == '\\') { if (ucsnext(nullptr, &pat) == 0) cerr(EXIT_FATAL, "Premature end of pattern"); - } else if (ch == rdelim) { - re.len = pat.p - re.p - w; + } else if (ch == rdelim) break; - } } - if (re.len == -1) - re.len = pat.p - re.p; - if (re.len == 0) { + if ((re.len = pat.p - re.p - w) == 0) { if (op.c != 'h') { cerr(EXIT_FATAL, "%s%c%s operator given empty regex", lquot, op.c, rquot); -- cgit v1.2.3