Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: printf, left-justification ignored in 5.0.8
On 2015-06-07 22:15:29 +0100, Stephane Chazelas wrote:
> BTW, there was a discussion lately on the Austin group mailing
> list confirming that the %20s should count bytes, not
> characters.
>
> That is in a UTF-8 locale
>
> printf '|%3s|\n' e é €
>
> should print:
>
> | e|
> | é|
> |€|
>
> not:
>
> | e|
> | é|
> | €|
>
> I find the zsh behaviour more useful though,
Well, it depends on the context. As I've said in
http://www.zsh.org/mla/workers/2012/msg00151.html
Yes, the number is the size in bytes, not in characters. I think
that the intent is to deal with internal structures (e.g. with
file formats where some fields have a fixed or limited size, and
the same syntax can be used in C to avoid buffer overflows).
I don't know if this is the real reason.
> especially considering that in zsh we can get the POSIX behaviour
> with:
>
> $ LC_ALL=C printf '|%3s|\n' e é €
> | e|
> | é|
> |€|
However the change of locale may affect other format specifiers,
like %f, and error messages.
> But note that to get proper alignment, rather than number of
> characters, the width of the glyphs should be considered
> instead anyway:
>
> $ printf '|%3b|\n' e '\ue9' 'e\u301' '\uff45'
> | e|
> | é|
> | é|
> | e|
>
> ksh93 has %3Ls for that:
>
> $ printf '|%3Ls|\n' e $'\ue9' $'e\u301' $'\uff45'
> | e|
> | é|
> | é|
> | e|
>
> (possibly uses wcswidth()).
This could be useful in zsh, and its support would be needed for
"emulate ksh".
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author