mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Make normalizeWhitespace remove \r as well.
This commit is contained in:
parent
9fba7668ec
commit
c587900c6f
@ -93,10 +93,11 @@ def normalizeWhitespace(s, removeNewline=True):
|
||||
"""Normalizes the whitespace in a string; \s+ becomes one space."""
|
||||
if not s:
|
||||
return str(s) # not the same reference
|
||||
starts_with_space = (s[0] in ' \n\t')
|
||||
ends_with_space = (s[-1] in ' \n\t')
|
||||
starts_with_space = (s[0] in ' \n\t\r')
|
||||
ends_with_space = (s[-1] in ' \n\t\r')
|
||||
if removeNewline:
|
||||
s = ' '.join(filter(bool, s.split('\n')))
|
||||
newline_re = re.compile('[\r\n]+')
|
||||
s = ' '.join(filter(bool, newline_re.split(s)))
|
||||
s = ' '.join(filter(bool, s.split('\t')))
|
||||
s = ' '.join(filter(bool, s.split(' ')))
|
||||
if starts_with_space:
|
||||
|
@ -369,6 +369,7 @@ class StrTest(SupyTestCase):
|
||||
self.assertEqual(f('foo bar'), 'foo bar')
|
||||
self.assertEqual(f('foo\nbar'), 'foo bar')
|
||||
self.assertEqual(f('foo\tbar'), 'foo bar')
|
||||
self.assertEqual(f('foo\rbar'), 'foo bar')
|
||||
|
||||
def testNItems(self):
|
||||
nItems = utils.str.nItems
|
||||
|
Loading…
Reference in New Issue
Block a user