Quoth Wolfgang Corcoran-Mathe:
>Breaking after the first null match follows the behavior of
>GNU ed. It has the virtue of simplicity.
>---
> ed.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/ed.c b/ed.c
>index ae9e6d7..6c05649 100644
>--- a/ed.c
>+++ b/ed.c
>_AT_@ -1005,10 +1005,10 @@ subline(int num, int nth)
> static size_t siz, cap;
>
> i = changed = siz = 0;
>- for (m = match(num); m; m = rematch(num)) {
>+ for (m = match(num); m && *lastmatch; m = rematch(num)) {
> addpre(&s, &cap, &siz);
> changed |= addsub(&s, &cap, &siz, nth, ++i);
>- if (eol || bol)
>+ if (eol || bol || matchs[0].rm_eo - matchs[0].rm_so == 0)
> break;
> }
> if (!changed)
>--
>2.9.0
Sorry, this last patch is simpleminded.
Given the following text and substitution, what should happen?
'glorious'
s/G*/P/g
sbase sed(1) gives us 'PgPlPoPrPiPoPuPsP' (matching every null
string), while GNU ed(1) gives an error. The above patch does
not throw an error, but rather performs the first substitution
and stops.
Is there a case in which a global substitution for a regex that
matches the null string is useful? Should we produce output like
'PgPlPoPrPiPoPuPsP' (which is almost certainly unwanted garbage)
or assume that such an expression is a mistake?
Regards,
--
wcm
Received on Mon Jul 25 2016 - 05:17:40 CEST