From: Guido van Rossum Date: Mon, 12 Feb 1996 23:59:54 +0000 (+0000) Subject: better way to normalize spaces in add_flowing_data X-Git-Tag: v1.4b1~360 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=93dc801b069dc3d4f628dc8c820ba32a51372ddf;p=python better way to normalize spaces in add_flowing_data --- diff --git a/Lib/formatter.py b/Lib/formatter.py index 50615f4176..363222e2a6 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