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 53011
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Feature request: ${(l[-3][0])var} to do left padding *without truncation*
- Date: Sat, 3 Aug 2024 21:31:52 +0100
- Archived-at: <https://zsh.org/workers/53011>
- In-reply-to: <20240803142241.zey7qejubi3piluk@chazelas.org>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxx>
- References: <20240803142241.zey7qejubi3piluk@chazelas.org>
2024-08-03 15:22:41 +0100, Stephane Chazelas:
[...]
> Same happens with -3 (though that doesn't seem to be documented):
>
> $ echo ${a//(#m)<->/${(l[-3][0])MATCH}}
> 001-012-123-234-345
[...]
Actually, the code has:
case 'l':
tt = 1;
/* fall through */
case 'r':
s++;
/* delimiter position */
del0 = s;
num = get_intarg(&s, &dellen);
if (num < 0)
goto flagerr;
So it looks like it was intended at some point for it to be an error for the
number to be negative, but get_intarg has:
if (ret < 0)
ret = -ret;
And earlier versions of the "l"/"r" handling code had:
case 'l':
tt = 1;
/* fall through */
case 'r':
t = get_strarg(++s);
if (!*t)
goto flagerr;
sav = *t;
*t = '\0';
d = dupstring(s + 1);
untokenize(d);
if ((num = mathevalarg(d, &d)) < 0)
num = -num;
The get_intarg was added in 3.0.1 in 1996.
Those l/r like most other flags added in 2.5 AFAICT and always accepted
negative padding length (sign ignored) though that was never documented.
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author