|
Message-Id: <66E91EF4-6D8E-4263-9386-24C9FF9DC2D9@gmail.com> Date: Thu, 16 Jun 2016 17:33:48 +0200 From: Julien Ramseier <j.ramseier@...il.com> To: musl@...ts.openwall.com Subject: Re: [PATCH] regex: support non-greedy quantifiers > Le 13 mars 2016 à 12:06, Julien Ramseier <j.ramseier@...il.com> a écrit : > > Here's a tiny patch to enable non-greedy regex quantifiers. > This is not specified by POSIX, but I think it's a useful > extension, and all the code for supporting it is already present. > > I tested this against the TRE and AT&T test suites (from NetBSD) > and didn't found any regressions. > However I don't know all the ins and outs of the implementation > and I may have missed something obvious. > > - Julien > > diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c > index 5fad98b..cc7d633 100644 > --- a/src/regex/regcomp.c > +++ b/src/regex/regcomp.c > @@ -979,6 +979,7 @@ static reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) > parse_iter: > for (;;) { > int min, max; > + int minimal = 0; > > if (*s!='\\' && *s!='*') { > if (!ere) > @@ -1014,11 +1015,16 @@ static reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) > if (*s == '?') > max = 1; > s++; > + /* Non-greedy */ > + if (ere && *s == '?') { > + minimal = 1; > + s++; > + } > } > if (max == 0) > ctx->n = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); > else > - ctx->n = tre_ast_new_iter(ctx->mem, ctx->n, min, max, 0); > + ctx->n = tre_ast_new_iter(ctx->mem, ctx->n, min, max, minimal); > if (!ctx->n) > return REG_ESPACE; > } > -- > 2.7.2 Ping?
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.