Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Feature request: ${(l[-3][0])var} to do left padding *without truncation*
- X-seq: zsh-workers 53017
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Feature request: ${(l[-3][0])var} to do left padding *without truncation*
- Date: Sun, 4 Aug 2024 07:44:26 +0100
- Archived-at: <https://zsh.org/workers/53017>
- In-reply-to: <CAH+w=7b3m4rZ_DezHQvZhF+-nsNsbnjrEPd3CvyiXBSLJf_B6g@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- References: <20240803142241.zey7qejubi3piluk@chazelas.org> <20240803203152.pa4nmmbfidvacsgx@chazelas.org> <20240803204252.5n4kf6jr5mxwxbs5@chazelas.org> <CAH+w=7b3m4rZ_DezHQvZhF+-nsNsbnjrEPd3CvyiXBSLJf_B6g@mail.gmail.com>
2024-08-03 14:28:03 -0700, Bart Schaefer:
> On Sat, Aug 3, 2024 at 1:42 PM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> >
> > And in $var:F[3]s/X/Y/ to repeat the substitution 3 times. This time no check
> > for negative values.
> On Sat, Aug 3, 2024 at 1:53 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > A closer examination of get_intarg() indicates that a negative return
> > means a parse error
Ah yes, sorry, I missed the point about get_intarg returning -1
upon error.
> This may mean that the :F case is hiding a bug.
Yes, negative values are handled like "f" (repeat as long as it
changes something), but get_intarg() only returns negative upon
error.
So for instance a=a; echo $a:F[1-]s/a/aa/ outputs an error but
runs into an infinite loop.
Maybe best would be to have get_intarg() return true/false and
the value by reference, and handle negative value on a case by
case basis in a more useful way:
${(I[-3])var/x/y} substitute the 3rd last occurrence
${(l[-3][0])var} pad to length 3 without truncating
${(r[-3][0])var} pad to length 3 without truncating
$var:F[-3]s/x/y/ error or treat like "f"
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author