mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix #1828820 [calibre.utils.titlecase does not preserve whitespace](https://bugs.launchpad.net/calibre/+bug/1828820)
This commit is contained in:
parent
7658dc65d9
commit
76d9f734e9
@ -56,9 +56,14 @@ def titlecase(text):
|
||||
|
||||
all_caps = upper(text) == text
|
||||
|
||||
words = re.split('\\s+', text)
|
||||
pat = re.compile(r'(\s+)')
|
||||
line = []
|
||||
for word in words:
|
||||
for word in pat.split(text):
|
||||
if not word:
|
||||
continue
|
||||
if pat.match(word) is not None:
|
||||
line.append(word)
|
||||
continue
|
||||
if all_caps:
|
||||
if UC_INITIALS.match(word):
|
||||
line.append(word)
|
||||
@ -83,7 +88,7 @@ def titlecase(text):
|
||||
hyphenated.append(CAPFIRST.sub(lambda m: icu_upper(m.group(0)), item))
|
||||
line.append("-".join(hyphenated))
|
||||
|
||||
result = " ".join(line)
|
||||
result = "".join(line)
|
||||
|
||||
result = SMALL_FIRST.sub(lambda m: '%s%s' % (
|
||||
m.group(1),
|
||||
|
Loading…
x
Reference in New Issue
Block a user