mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
even better way to normalize spaces in add_flowing_data
This commit is contained in:
parent
93dc801b06
commit
7bb7ecd39e
1 changed files with 9 additions and 17 deletions
|
@ -110,26 +110,18 @@ class AbstractFormatter:
|
||||||
if not data: return
|
if not data: return
|
||||||
# The following looks a bit convoluted but is a great improvement over
|
# The following looks a bit convoluted but is a great improvement over
|
||||||
# data = regsub.gsub('[' + string.whitespace + ']+', ' ', data)
|
# data = regsub.gsub('[' + string.whitespace + ']+', ' ', data)
|
||||||
if data[0] in string.whitespace:
|
prespace = data[0] in string.whitespace
|
||||||
head = ' '
|
postspace = data[-1] in string.whitespace
|
||||||
else:
|
data = string.join(string.split(data))
|
||||||
head = ''
|
if self.nospace and prespace:
|
||||||
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
|
if not data: return
|
||||||
elif self.softspace and data[0] != ' ':
|
prespace = 0
|
||||||
data = ' ' + data
|
elif self.softspace:
|
||||||
|
prespace = 1
|
||||||
self.nospace = self.softspace = 0
|
self.nospace = self.softspace = 0
|
||||||
if data[-1] == ' ':
|
if postspace:
|
||||||
data = data[:-1]
|
|
||||||
self.softspace = 1
|
self.softspace = 1
|
||||||
|
if prespace: data = ' ' + data
|
||||||
self.writer.send_flowing_data(data)
|
self.writer.send_flowing_data(data)
|
||||||
|
|
||||||
def add_literal_data(self, data):
|
def add_literal_data(self, data):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue