core: Fix normalizeWhitespace handling of new lines.

This commit is contained in:
Valentin Lorentz 2013-01-04 22:28:44 +01:00
parent 29e13a9061
commit fe39d35b2f
2 changed files with 6 additions and 3 deletions

View File

@ -55,13 +55,14 @@ def rsplit(s, sep=None, maxsplit=-1):
else: else:
return s.rsplit(sep, maxsplit) return s.rsplit(sep, maxsplit)
def normalizeWhitespace(s, removeNewline=False): def normalizeWhitespace(s, removeNewline=True):
"""Normalizes the whitespace in a string; \s+ becomes one space.""" """Normalizes the whitespace in a string; \s+ becomes one space."""
if not s: if not s:
return str(s) # not the same reference return str(s) # not the same reference
starts_with_space = (s[0] in ' \n\t') starts_with_space = (s[0] in ' \n\t')
ends_with_space = (s[-1] in ' \n\t') ends_with_space = (s[-1] in ' \n\t')
s = ('' if removeNewline else ' ').join(filter(bool, s.split('\n'))) if removeNewline:
s = ' '.join(filter(bool, s.split('\n')))
s = ' '.join(filter(bool, s.split('\t'))) s = ' '.join(filter(bool, s.split('\t')))
s = ' '.join(filter(bool, s.split(' '))) s = ' '.join(filter(bool, s.split(' ')))
if starts_with_space: if starts_with_space:

View File

@ -39,7 +39,7 @@ _ = PluginInternationalization()
@internationalizeDocstring @internationalizeDocstring
def foo(): def foo():
'The operation succeeded.' """The operation succeeded."""
pass pass
class I18nTestCase(SupyTestCase): class I18nTestCase(SupyTestCase):
@ -49,6 +49,8 @@ class I18nTestCase(SupyTestCase):
self.assertEqual(_(msg_en), msg_fr) self.assertEqual(_(msg_en), msg_fr)
conf.supybot.language.setValue('en') conf.supybot.language.setValue('en')
self.assertEqual(_(msg_en), msg_en) self.assertEqual(_(msg_en), msg_en)
multiline = '%s\n\n%s' % (msg_en, msg_en)
self.assertEqual(_(multiline), multiline)
def testDocstring(self): def testDocstring(self):
self.assertEqual(foo.__doc__, msg_en) self.assertEqual(foo.__doc__, msg_en)