zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: printf, left-justification ignored in 5.0.8
Date: Sun, 7 Jun 2015 22:15:29 +0100	[thread overview]
Message-ID: <20150607211529.GA13370@chaz.gmail.com> (raw)
In-Reply-To: <30271.1433709564@thecus.kiddle.eu>

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


  reply	other threads:[~2015-06-07 21:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20150607081142.GF15174@isis.sigpipe.cz>
2015-06-07 20:39 ` Oliver Kiddle
2015-06-07 21:15   ` Stephane Chazelas [this message]
2015-06-12 11:30     ` Vincent Lefevre
2015-06-12 12:31       ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150607211529.GA13370@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).