summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-02-12 23:59:54 (GMT)
committerGuido van Rossum <guido@python.org>1996-02-12 23:59:54 (GMT)
commit93dc801b069dc3d4f628dc8c820ba32a51372ddf (patch)
tree75882fd551808e59e0e8ce126997c7aa9ce44c8d
parentf69da220bfe1b8a0b8a061a0463fbb7d542ffa0f (diff)
downloadcpython-93dc801b069dc3d4f628dc8c820ba32a51372ddf.zip
cpython-93dc801b069dc3d4f628dc8c820ba32a51372ddf.tar.gz
cpython-93dc801b069dc3d4f628dc8c820ba32a51372ddf.tar.bz2
better way to normalize spaces in add_flowing_data
-rw-r--r--Lib/formatter.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/formatter.py b/Lib/formatter.py
index 50615f4..363222e 100644
--- a/Lib/formatter.py
+++ b/Lib/formatter.py
@@ -6,8 +6,6 @@ import sys
AS_IS = None
-whitespace = '[' + string.whitespace + ']+'
-
class NullFormatter:
@@ -110,7 +108,19 @@ class AbstractFormatter:
def add_flowing_data(self, data):
if not data: return
- data = regsub.gsub(whitespace, ' ', data)
+ # The following looks a bit convoluted but is a great improvement over
+ # data = regsub.gsub('[' + string.whitespace + ']+', ' ', data)
+ if data[0] in string.whitespace:
+ head = ' '
+ else:
+ head = ''
+ if data[-1] in string.whitespace:
+ tail = ' '
+ else:
+ tail = ''
+ data = head + string.join(string.split(data))
+ if data != ' ': data = data + tail
+ #
if self.nospace and data[0] == ' ':
data = data[1:]
if not data: return