]> granicus.if.org Git - python/commitdiff
Issue #4163: textwrap module: allow word splitting on a hyphen preceded by a non...
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 13 Dec 2008 23:20:54 +0000 (23:20 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 13 Dec 2008 23:20:54 +0000 (23:20 +0000)
Lib/test/test_textwrap.py
Lib/textwrap.py
Misc/NEWS

index 1cbd9cece0e1891957eddebe3ce3b63ac3f6deaa..ffd59c34d343a8dc284c3475639af583073e0696 100644 (file)
@@ -365,6 +365,14 @@ What a mess!
         self.assertRaises(ValueError, wrap, text, 0)
         self.assertRaises(ValueError, wrap, text, -1)
 
+    def test_no_split_at_umlaut(self):
+        text = "Die Empf\xe4nger-Auswahl"
+        self.check_wrap(text, 13, ["Die", "Empf\xe4nger-", "Auswahl"])
+
+    def test_umlaut_followed_by_dash(self):
+        text = "aa \xe4\xe4-\xe4\xe4"
+        self.check_wrap(text, 7, ["aa \xe4\xe4-", "\xe4\xe4"])
+
 
 class LongWordTestCase (BaseTestCase):
     def setUp(self):
index 867b9d9f27ce14d3fe3c150705e58a5197a67136..1f2e9b4a7996f606f0af71f51563c85696a556a1 100644 (file)
@@ -76,7 +76,7 @@ class TextWrapper:
     # (after stripping out empty strings).
     wordsep_re = re.compile(
         r'(\s+|'                                  # any whitespace
-        r'[^\s\w]*\w+[a-zA-Z]-(?=\w+[a-zA-Z])|'   # hyphenated words
+        r'[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|'   # hyphenated words
         r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))')   # em-dash
 
     # This less funky little regex just split on recognized spaces. E.g.
index aaa65c587e40c2ff533bf2ae1b018c6b1ca0eab7..e31bb0b810180a5bf598f1159bdbafafe6c17961 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -45,6 +45,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #4163: textwrap module: allow word splitting on a hyphen preceded by
+  a non-ASCII letter.
+
 - Issue #4616: TarFile.utime(): Restore directory times on Windows.
 
 - Issue #4021: tokenize.detect_encoding() now raises a SyntaxError when the