Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ${(S)%%*} doesn't match the empty string (was: Re: [PATCH] zshexpn: Expand documentation of (S) (was: Re: [Bug] S-flag imposes non-greedy match where it shouldn't))



On Mon, 2019-12-30 at 21:24 +0000, Daniel Shahaf wrote:
>      1	% set -- foo
>      2	% p ${1#*}
>      3	foo
>      4	% p ${1%*}
>      5	foo
>      6	% p ${(S)1#*}
>      7	foo
>      8	% p ${(S)1%*}
>      9	foo
>     10	% p ${1##*}
>     11	
>     12	% p ${1%%*}
>     13	
>     14	% p ${(S)1##*}
>     15	
>     16	% p ${(S)1%%*}
>     17	fo
>     18	% 
> 
> Isn't this an implementation bug?

The last one certainly doesn't look right.

The top-and-tail operators are already complicated without the substring
matching, which was bolted on later wihtout a particularly good set of
ground rules about how the loops looking for the longest or shortest
match and for a given substring interacted in the case of pattern
matches where the match itself can have a variable length.  Furthermore,
as you'll see, a lot of the various cases start / end, longest /
shortest, full / substring are implemented separately (though in return
that makes it a bit easier to fix a problem case without disturbing
others).  So it's actually quite easy for something like this to lie
around for a long time.

pws



Messages sorted by: Reverse Date, Date, Thread, Author