Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Jan 2009 00:05:28 +0100
From:      Svein Halvor Halvorsen <svein.h@lvor.halvorsen.cc>
To:        Chuck Swiger <cswiger@mac.com>
Cc:        questions@freebsd.org
Subject:   Re: printf and utf-8
Message-ID:  <497E41B8.2030203@lvor.halvorsen.cc>
In-Reply-To: <0B02CEE8-D38A-4D94-B76D-49721BDDACF0@mac.com>
References:  <497E31EE.9010202@lvor.halvorsen.cc> <0B02CEE8-D38A-4D94-B76D-49721BDDACF0@mac.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Chuck Swiger wrote:
> On Jan 26, 2009, at 1:58 PM, Svein Halvor Halvorsen wrote:
>> As far as I can see, printf is not calculating strings lengths 
>> correctly when using utf-8 encoding. Either that, or I'm using byte 
>> count, and can't find the character count :-/
> 
> printf(1) explicitly states that it works with ASCII and ANSI 
> X3.159-1989 (``ANSI C89'') character escapes, and it also notes:
> 
>      Multibyte characters are not recognized in format strings (this is 
> only a
>      problem if `%' can appear inside a multibyte character).
> 
> Some platforms have a printf_l(3) which is locale/xlocale-aware, but 
> there doesn't seem to be a corresponding CLI utility which understands 
> Unicode/UTF8/widechars.

Thanks for your explanation.

Do you have a suggestion to solve the following problem without using 
printf(1):

I have a text file that I want to print in a "box" on a terminal from a 
shell script. Now I've padded the lines with spaces to a certain length 
using printf %-70s and appended the box drawing character. Is there 
another simple way that will work with utf-8?


	sv.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?497E41B8.2030203>