Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: (LC_ALL=C; set -x 128 129; printf "%s\n" ${(#)@} | hexdump -C)
- X-seq: zsh-workers 52111
- From: "Jun. T" <takimoto-j@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: (LC_ALL=C; set -x 128 129; printf "%s\n" ${(#)@} | hexdump -C)
- Date: Fri, 1 Sep 2023 02:38:21 +0900
- Archived-at: <https://zsh.org/workers/52111>
- In-reply-to: <CAH+w=7b58OFubjUOdYuqm0U3hYPKFbX-GSuj7R7H6T8jmtTG2Q@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <20230830072753.hhveg7teosubwzq7@chazelas.org> <CAH+w=7b58OFubjUOdYuqm0U3hYPKFbX-GSuj7R7H6T8jmtTG2Q@mail.gmail.com>
> 2023/08/31 4:45, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Doc for (#) says:
>
> If the MULTIBYTE option is set and the number is greater than 127
> (i.e. not an ASCII character) it is treated as a Unicode
> character.
It seems that this translation succeeds only if UTF-8 locale is in use.
The translation is done in function substevalchar(), but in C locale it
fails to convert and fallbacks to 'no translation':
$ LC_ALL=C zsh -f
% n=128
% printf "%s\n" ${(#)n} | hexdump -C
00000000 80 0a |..|
00000002
substevalchar() calls getkeystring() for the conversion, and
wctomb() (utils.c:6983) fails (returns -1), and zerr() sets
errflag.
If we use an array instead of sclar:
% a=( 128 129 )
% printf "%s\n" ${(#)a} | hexdump -C
00000000 22 0a 22 |"."|
00000003
In this case, errflag is set when translating a[0]=128, but it is
not reset and still set to 1 when substevalchar() is called for a[1].
Then substevalchar() immediately returns NULL (subst.c:1496).
Now paramsubst() sets haserr=1 (subst.c:3592) and returns NULL at
line 3609 (although errflag is reset at line 3606),
and stringsubst() also returns NULL (line 327),
and prefork() quits at line 146 (probably before removing " " from
t"%s\n").
So we need to reset (or save/restore) errflag somewhere...
And, with multibyte option on but with C locale, what is the
correct behavior of ${(#)n} for n > 127 ?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author