Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: printf, left-justification ignored in 5.0.8



2015-06-07 22:39:24 +0200, Oliver Kiddle:
> Roman Neuhauser wrote:
> > 
> > 5.0.8:
> > 
> > % printf "x:%-20s:y\n" fubar
> > x:               fubar:y
> 
> That'll be my fault for not checking thoroughly enough. The - flag is
> fine for numeric values but for strings it seems there is separate code
> to allow for UTF-8 which looks in the flags array. The patch should
> fix this, adds a test and makes the maximum specification length test
> include the ' flag.
[...]

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, especially
considering that in zsh we can get the POSIX behaviour with:

$ LC_ALL=C printf '|%3s|\n' e é €
|  e|
| é|
|€|

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()).

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author