Re: printf and utf-8
On Tue, Jan 27, 2009 at 12:05:28AM +0100, Svein Halvor Halvorsen wrote: 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? What's your perl like? http://search.cpan.org/~sadahiro/String-Multibyte-1.05/Multibyte.pm http://perldoc.perl.org/perlfaq6.html#How-can-I-match-strings-with-multibyte-characters%3f Looks like they might be interesting. Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: printf and utf-8
On Mon, Jan 26, 2009 at 03:03:44PM -0800, Chuck Swiger wrote: On Jan 26, 2009, at 3:05 PM, Svein Halvor Halvorsen wrote: 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? My first thought was about dialog(1), but I'm not sure whether that deals with UTF8 any better...? There's dialog(1) in the FreeBSD tree, and dialog(1) on my website. The latter can work with UTF-8 (if it's built with ncursesw). But that's a little different from printf... -- Thomas E. Dickey http://invisible-island.net ftp://invisible-island.net pgpQnR3vgPxNo.pgp Description: PGP signature
Re: printf and utf-8
On Monday 26 January 2009 12:58:06 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 :-/ Eg: $ printf |%-10s| æøå |æøå| $ printf |%-10s| 123 |123 | I'm on 7.1-p2 Does this work on an xterm (or anything else then the FreeBSD console) with correct LANG variable set? The FreeBSD console does not work with utf-8 (yet), allthough I would not think it should affect printf's character counting, still.it haunts me. -- Mel Problem with today's modular software: they start with the modules and never get to the software part. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
printf and utf-8
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 :-/ Eg: $ printf |%-10s| æøå |æøå| $ printf |%-10s| 123 |123 | I'm on 7.1-p2 sv. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: printf and utf-8
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 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: printf and utf-8
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. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: printf and utf-8
On Jan 26, 2009, at 3:05 PM, Svein Halvor Halvorsen wrote: 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? My first thought was about dialog(1), but I'm not sure whether that deals with UTF8 any better...? -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: printf and utf-8
Chuck Swiger wrote: On Jan 26, 2009, at 3:05 PM, Svein Halvor Halvorsen wrote: 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? My first thought was about dialog(1), but I'm not sure whether that deals with UTF8 any better...? No, it doesn't seem to. Also it clears the entire screen to draw the box. I only want a small box, and not clear the screen, and I don't want a OK-button or any other user interaction. Just print the simple box, then whatever follows from the script should print after it. Nevertheless, thanks for your help and your time! sv. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org