Skip to content

Commit

Permalink
fix for titlecase
Browse files Browse the repository at this point in the history
  • Loading branch information
drkane committed Apr 17, 2021
1 parent 4147f15 commit b239965
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions findthatcharity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def title_exceptions(word, **kwargs):
"clwb",
"drs",
]:
return None
return word_test.title()

# words with number ordinals
if bool(ORD_NUMBERS_RE.search(word_test.lower())):
Expand All @@ -73,16 +73,24 @@ def title_exceptions(word, **kwargs):
# check for possesive apostrophes
if s == "'" and dots[-1].upper() == "S":
return s.join(
[titlecase.titlecase(i, title_exceptions) for i in dots[:-1]]
[
titlecase.titlecase(i, callback=title_exceptions)
for i in dots[:-1]
]
+ [dots[-1].lower()]
)
# check for you're and other contractions
if word_test.upper() in ["YOU'RE", "DON'T", "HAVEN'T"]:
return s.join(
[titlecase.titlecase(i, title_exceptions) for i in dots[:-1]]
[
titlecase.titlecase(i, callback=title_exceptions)
for i in dots[:-1]
]
+ [dots[-1].lower()]
)
return s.join([titlecase.titlecase(i, title_exceptions) for i in dots])
return s.join(
[titlecase.titlecase(i, callback=title_exceptions) for i in dots]
)

# words with no vowels in (treat as acronyms)
if not bool(VOWELS.search(word_test)):
Expand All @@ -106,7 +114,7 @@ def to_titlecase(s, sentence=False):
return "".join([sent.capitalize() for sent in re.split(SENTENCE_SPLIT, s)])

# try titlecasing
s = titlecase.titlecase(s, title_exceptions)
s = titlecase.titlecase(s, callback=title_exceptions)

# Make sure first letter is capitalise
return s[0].upper() + s[1:]
Expand Down

0 comments on commit b239965

Please sign in to comment.