Added unCommaThe function.

This commit is contained in:
Jeremy Fincher 2003-08-23 07:57:04 +00:00
parent 17478daca2
commit 53d883710e
2 changed files with 13 additions and 0 deletions

View File

@ -271,4 +271,12 @@ def commaAndify(seq):
L[-1] = 'and %s' % L[-1]
return ', '.join(L)
_unCommaTheRe = re.compile(r'(.*),\s*(the)$', re.I)
def unCommaThe(s):
m = _unCommaTheRe.match(s)
if m is not None:
return '%s %s' % (m.group(2), m.group(1))
else:
return s
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -148,5 +148,10 @@ class UtilsTest(unittest.TestCase):
self.assertEqual(L, original)
self.failUnless(utils.commaAndify(sets.Set(L)))
def testUnCommaThe(self):
self.assertEqual(utils.unCommaThe('foo bar'), 'foo bar')
self.assertEqual(utils.unCommaThe('foo bar, the'), 'the foo bar')
self.assertEqual(utils.unCommaThe('foo bar, The'), 'The foo bar')
self.assertEqual(utils.unCommaThe('foo bar,the'), 'the foo bar')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: