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*



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