Hi Sue,

On 2010年09月14日 01:33, Sue Sohn wrote:
:
The first bullet is the expectation. The list in question is a list of characters, so getting the length of the string (concatenated characters) is the desired result.

I see. Attached are a sample modification to textwidth() and
to its test case.

Thanks,
Takeshi
--- i18n.py.sue	Tue Sep 14 14:07:26 2010
+++ i18n.py.mine	Tue Sep 14 15:19:08 2010
@@ -59,12 +59,22 @@
 
 def textwidth(text):
     ''' Count column width needed for given string.
+    When a list is given, count total columns needed for all strings
+    in the list.
     '''
+    if isinstance(text, list):
+        # Use "\n" instead of "" to make expandtabs() work correctly
+        text = "\n".join(text)
+
+    if not isinstance(text, basestring):
+        raise TypeError('textwidth() accepts basestring or list of it only.')
+
     if isinstance(text, str):
         text = text.decode(get_encoding())
-    if isinstance(text, basestring):
-        text = text.expandtabs(4)
 
+    # Remove "\n" after expanding tabs
+    text = text.expandtabs(4).replace("\n", "")
+
     width_total = 0
 
     for char in text:
diff -r 9417f16611f0 usr/src/cmd/text-install/osol_install/text_install/test/test_i18n.py
--- a/usr/src/cmd/text-install/osol_install/text_install/test/test_i18n.py	Wed Sep 01 15:24:23 2010 -0700
+++ b/usr/src/cmd/text-install/osol_install/text_install/test/test_i18n.py	Tue Sep 14 15:43:59 2010 +0900
@@ -89,6 +89,12 @@
         self.assertEqual(textwidth(u'\tA\u00c0\u3042'), 4 + 1 + 1 + 2)
         self.assertEqual(textwidth(u'\tA\u00c0\u3042'.encode(get_encoding())),
                          4 + 1 + 1 + 2)
+        # when list is given
+        self.assertEqual(textwidth([u'\tA\u3042\u3044', u'B\t\u3046']),
+                         4 + 1 + 2 + 2 + 1 + 3 + 2)
+        self.assertEqual(textwidth([u'\tA\u3042\u3044'.encode(get_encoding()),
+                                    u'B\t\u3046'.encode(get_encoding())]),
+                         4 + 1 + 2 + 2 + 1 + 3 + 2)
 
     def test_fit_text_truncate(self):
         ''' test fit_text_truncate() '''
_______________________________________________
caiman-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/caiman-discuss

Reply via email to