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))
- X-seq: zsh-workers 45168
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: 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))
- Date: Mon, 30 Dec 2019 22:34:07 +0000
- In-reply-to: <20191230212420.gk2jkimlk3epfdha@tarpaulin.shahaf.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVDx6WEFcZFS3TQ6+rF1YpA3jkD5sWwr0LCNE_c5MYkxVg@mail.gmail.com> <20191228210017.2cdgwgpqrssrfhgp@tarpaulin.shahaf.local2> <CAKc7PVD7UCc5yqDays=xCVFa=-Ns6phhqLd2se_+3iKNzOr5tA@mail.gmail.com> <20191229020534.oqh5ri3nqealx4hj@tarpaulin.shahaf.local2> <CAKc7PVDhkOm9gQ-mxRnyh=MT_onqvsQAzymcpV+AguanHa7nig@mail.gmail.com> <20191230180036.u33ixxe5pjjk7lal@tarpaulin.shahaf.local2> <CAN=4vMor_OBci8FRDkQjM8GfpGuM2A58D=nN+WoDgpQrpRKBzg@mail.gmail.com> <CAKc7PVAXLpKqZvmbazZK=mvcz8T-AHJXKusut6aEjkkSLzgdbw@mail.gmail.com> <CAN=4vMqyNngcWKH7TfN14Rh+5vyDJ-v8ciNiF7OHrNQG=OLvDA@mail.gmail.com> <CAKc7PVA-G9J1sAYdEJ-6GtqQnTx3RyJP6x-jM3JEYqX6NV3Gpg@mail.gmail.com> <20191230212420.gk2jkimlk3epfdha@tarpaulin.shahaf.local2>
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