Skip to content

Commit ff44043

Browse files
authored
Merge pull request ppannuto#28 from Garrett-R/master
More robust against unicode chars
2 parents 4dc9aff + 20a40c8 commit ff44043

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

titlecase/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
SMALL_LAST = re.compile(r'\b(%s)[%s]?$' % (SMALL, PUNCT), re.I)
2626
SUBPHRASE = re.compile(r'([:.;?!\-–‒—―][ ])(%s)' % SMALL)
2727
APOS_SECOND = re.compile(r"^[dol]{1}['‘]{1}[a-z]+(?:['s]{2})?$", re.I)
28-
ALL_CAPS = re.compile(r'^[A-Z\s\d%s]+$' % PUNCT)
2928
UC_INITIALS = re.compile(r"^(?:[A-Z]{1}\.{1}|[A-Z]{1}\.{1}[A-Z]{1})+$")
3029
MAC_MC = re.compile(r"^([Mm]c|MC)(\w.+)")
3130

@@ -64,7 +63,7 @@ def titlecase(text, callback=None, small_first_last=True):
6463
lines = re.split('[\r\n]+', text)
6564
processed = []
6665
for line in lines:
67-
all_caps = ALL_CAPS.match(line)
66+
all_caps = line.upper() == line
6867
words = re.split('[\t ]', line)
6968
tc_line = []
7069
for word in words:

titlecase/tests.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
"episode 7 – The force awakens",
125125
"Episode 7 – The Force Awakens"
126126
),
127+
(
128+
"THE CASE OF X ≤ 7",
129+
"The Case of X ≤ 7"
130+
),
131+
(
132+
"the case of X ≤ 7",
133+
"The Case of X ≤ 7"
134+
),
127135
(
128136
'"Nothing to Be Afraid of?"',
129137
'"Nothing to Be Afraid Of?"'
@@ -247,12 +255,6 @@
247255
)
248256

249257

250-
def test_all_caps_regex():
251-
"""Test - all capitals regex"""
252-
from titlecase import ALL_CAPS
253-
assert bool(ALL_CAPS.match('THIS IS ALL CAPS')) is True
254-
255-
256258
def test_initials_regex():
257259
"""Test - uppercase initials regex with A.B"""
258260
from titlecase import UC_INITIALS

0 commit comments

Comments
 (0)