Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: #% anchoring doesn't work with (S)
- X-seq: zsh-workers 51349
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: #% anchoring doesn't work with (S)
- Date: Thu, 2 Feb 2023 11:44:00 +0100
- Archived-at: <https://zsh.org/workers/51349>
- In-reply-to: <CAHYJk3R9UGo=UTo=brTqHQnmrxTHiRxaoN1Q_9QfN4LWrsk7gQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAKc7PVA=Beup8-GyjpxCst0=Ne_-v1yjYqn46YuRMTRuvTpteg@mail.gmail.com> <CAKc7PVBi-_jW2UZkOaxpOqUG=V+DS8sU814nVp4Yj7Su28Kqpg@mail.gmail.com> <CAHYJk3R9UGo=UTo=brTqHQnmrxTHiRxaoN1Q_9QfN4LWrsk7gQ@mail.gmail.com>
On 2/2/23, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On 2/2/23, Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
>> Could the bug be fixed? It already makes #% pretty much unusable for a
>> backward compatible software, yet in say 4 years this would be changed,
>> if
>> the bug would be fixed today
>
> Why would you use (S) (shortest possible match) with #% (match the
> entire string)? It will obviously never have a useful effect other
> than doing nothing.
>
> That said, compgetmatch() does this, which is probably your problem
> (it gives no real motivation for why it does this)
> /*
> * Search is anchored to the end of the string if we want to match
> * it all, or if we are matching at the end of the string and not
> * using substrings.
> */
> if ((*flp & SUB_ALL) || ((*flp & SUB_END) && !(*flp & SUB_SUBSTR)))
> patflags &= ~PAT_NOANCH;
Actually this is probably not it, it works if you don't use just a *
as the pattern:
% INPUT=ABCABCABC; INPUT=${(S)INPUT//#%((#b)(A*C))/°match°}; print
$INPUT $match
°match° ABCABCABC
% INPUT=ABCABCABC; INPUT=${INPUT//#%((#b)(A*C))/°match°}; print $INPUT
$match
°match° ABCABCABC
% INPUT=ABCABCABC; INPUT=${(S)INPUT//((#b)(A*C))/°match°}; print
$INPUT $match
°match°°match°°match° ABC
so it feels more like the * itself remembers the S flag but not the #%
flags. (But still, specifying the (S) flag in this case is useless in
the first place, so just don't specify it and your code will be
compatible with every version).
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author