From 3ab099d9efc1755de0c59d5dc7139eb881af650e Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Wed, 18 Dec 2019 09:21:15 -0800 Subject: [PATCH] Preserve already OKish entries. --- cleanbasestation.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cleanbasestation.py b/cleanbasestation.py index d402933..911969f 100644 --- a/cleanbasestation.py +++ b/cleanbasestation.py @@ -62,14 +62,22 @@ NOT_TITLE_CASE = [ TITLE_CASE_EXCEPTION_RE = re.compile('[0-9]') +def contains_upper_and_lower(s): + return any(c.isupper() for c in s) and any(c.islower() for c in s) + + def title_case(s): - if (TITLE_CASE_EXCEPTION_RE.search(s) or + if (contains_upper_and_lower(s) or + TITLE_CASE_EXCEPTION_RE.search(s) or s in NOT_TITLE_CASE or (len(s) <= 3 and s not in TITLE_CASE)): return s else: return s.title() + +# TODO: MCDONNELL -> McDonnell + def fix_type(s): if s is not None: tokens = [p for p in s.split(' ') if p]