summaryrefslogtreecommitdiff
path: root/textutils.py
diff options
context:
space:
mode:
authorSylvain <syt@logilab.fr>2007-01-10 17:29:14 +0100
committerSylvain <syt@logilab.fr>2007-01-10 17:29:14 +0100
commit63c7d018f7553e36ccc365aebb2d0512da246b1a (patch)
tree4e950b6215bc0b9ea1e5a66e24c0640da9c8ce33 /textutils.py
parentc880a246f4647b1f395d054c42d455982c6bae2e (diff)
downloadlogilab-common-63c7d018f7553e36ccc365aebb2d0512da246b1a.tar.gz
fix rest normalization to avoid data loss
Diffstat (limited to 'textutils.py')
-rw-r--r--textutils.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/textutils.py b/textutils.py
index c26f932..ba0bffa 100644
--- a/textutils.py
+++ b/textutils.py
@@ -156,11 +156,17 @@ def normalize_rest_paragraph(text, line_len=80, indent=''):
for line in text.splitlines():
line = indent + toreport + _NORM_SPACES_RGX.sub(' ', line.strip())
toreport = ''
- if len(line) > line_len:
+ while len(line) > line_len:
# too long line, need split
line, toreport = splittext(line, line_len)
- toreport += ' '
- lines.append(line)
+ lines.append(line)
+ if toreport:
+ line = indent + toreport + ' '
+ toreport = ''
+ else:
+ line = ''
+ if line:
+ lines.append(line.strip())
return linesep.join(lines)
def splittext(text, line_len):
@@ -179,7 +185,7 @@ def splittext(text, line_len):
pos = min(len(text), line_len)
while len(text) > pos and text[pos] != ' ':
pos += 1
- return text[:pos], text[pos+1:]
+ return text[:pos], text[pos+1:].strip()
def get_csv(string, sep=','):