Skip to content

Commit

Permalink
Make normalizeWhitespace remove \r as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Aug 30, 2015
1 parent 9fba766 commit c587900
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/utils/str.py
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions test/test_utils.py
Expand Up @@ -369,6 +369,7 @@ def testNormalizeWhitespace(self):
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
Expand Down

0 comments on commit c587900

Please sign in to comment.