Package: python2.4 Version: 2.4.2-1 Severity: wishlist The C function wcswidth() is used to determine the number of terminal cells that a wide-character string will require. This is essential for programs that generate terminal output, might operate in Unicode locales and need to calculate string widths in order to perform text formatting operations.
The obvious thing to me would be a new method (width(), or perhaps terminalwidth() if you prefer a more generic name) on strings that returns the string length for non-unicode strings, and the result of wcswidth() for Unicode strings. So, >>> s = 'a' >>> type(s) <type 'str'> >>> len(s) 1 >>> s.width() 1 >>> s = 'と' >>> type(s) <type 'str'> >>> len(s) 3 >>> s.width() 3 >>> us = s.decode('utf-8') >>> us u'\u3068' >>> type(us) <type 'unicode'> >>> len(us) 1 >>> us.width() 2 Daniel -- System Information: Debian Release: testing/unstable APT prefers unstable APT policy: (500, 'unstable'), (1, 'experimental') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.14-1-686 Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
signature.asc
Description: Digital signature