printf and utf-8

Chuck Swiger cswiger at mac.com
Mon Jan 26 14:25:15 PST 2009


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.

Regards,
-- 
-Chuck



More information about the freebsd-questions mailing list