From 53d883710ed7706dc5b8843ce0b975c87532a28e Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 23 Aug 2003 07:57:04 +0000 Subject: [PATCH] Added unCommaThe function. --- src/utils.py | 8 ++++++++ test/test_utils.py | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/utils.py b/src/utils.py index 4fd0dfde7..d059e4640 100755 --- a/src/utils.py +++ b/src/utils.py @@ -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: diff --git a/test/test_utils.py b/test/test_utils.py index 1fd26b9c5..5446bf1eb 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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: