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: Fri, 12 Jun 2015 13:31:45 +0100	[thread overview]
Message-ID: <20150612123145.GA6859@chaz.gmail.com> (raw)
In-Reply-To: <20150612113050.GA21806@ypig.lip.ens-lyon.fr>

2015-06-12 13:30:50 +0200, Vincent Lefevre:
> 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.

I beleive the real reason was to align on C printf (not wprintf
for instance) (makes little sense to me)

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

Well, that's a general problem with LC_* handling. Here however
it can be worked around by using several invocations of printf.

[...]
> > 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".
[...]

While I agree that could be useful feature, note that zsh is not
(and will never be I hope) a superset of ksh93. The emulation
mode changes some behaviour that othewise differ from ksh. It
covers mostly ksh88, and zsh has a few features from ksh93 but
that's about it.

-- 
Stephane


      reply	other threads:[~2015-06-12 12:52 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
2015-06-12 11:30     ` Vincent Lefevre
2015-06-12 12:31       ` Stephane Chazelas [this message]

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=20150612123145.GA6859@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).