On Tue, 5 Sep 2017 10:19:45 -0500, Paul Gilmartin <paulgboul...@aim.com> wrote:

>What language(s) cleanly handle vertical alignment of formatted text output 
>when
>the text contains UTF-16 supplemental/surrogate (not in the BMP) characters?
>Here's an example of /bin/printf's failure for similar input with UTF-8 on 
>MacOS:
>
>The script:
>printf "%-22s+++\n" "Hello World."
>printf "%-22s+++\n" "Привет мир."
>printf "%-22s+++\n" "Bonjour le monde."
>
>writes:
>Hello World.          +++
>Привет мир.  +++
>Bonjour le monde.     +++
>
>I wish the "+++" would line up (at least in a monospaced font).
>What sort of PICTURE would work for such, not restricting to BMP?

It would take more than a simple script like that, but with programming it can 
be done. I have a Python program that does it, for example. The key is 
understanding that some characters don't take up any space when printed 
(combining characters, for example), and therefore don't contribute to the 
length of the output string. When those characters are present you need to pad 
the end with blanks if you want a fixed width output string.

Python has Unicode functions that let you examine the characteristics of the 
characters within a string so you can figure out the proper length when 
printed, but I'm not aware of anything built-in like a print function that does 
that automatically. It would be handy.

Presumably one could do that in other languages, too. And presumably one could 
implement a print function that did that automatically. Perhaps someone has, or 
perhaps some language can do it automatically.

-- 
Walt

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to