|
18 | 18 | import regex |
19 | 19 | except ImportError: |
20 | 20 | import re as regex |
| 21 | + REGEX_AVAILABLE = False |
| 22 | +else: |
| 23 | + REGEX_AVAILABLE = True |
21 | 24 |
|
22 | 25 | __all__ = ['titlecase'] |
23 | 26 | __version__ = '2.1.0' |
|
26 | 29 | PUNCT = r"""!"“#$%&'‘()*+,\-–‒—―./:;?@[\\\]_`{|}~""" |
27 | 30 |
|
28 | 31 | SMALL_WORDS = regex.compile(r'^(%s)$' % SMALL, regex.I) |
29 | | -INLINE_PERIOD = regex.compile(r'[\p{Letter}][.][\p{Letter}]', regex.I) |
30 | | -UC_ELSEWHERE = regex.compile(r'[%s]*?[\p{Letter}]+[\p{Uppercase_Letter}]+?' % PUNCT) |
31 | | -CAPFIRST = regex.compile(r"^[%s]*?([\p{Letter}])" % PUNCT) |
| 32 | + |
32 | 33 | SMALL_FIRST = regex.compile(r'^([%s]*)(%s)\b' % (PUNCT, SMALL), regex.I) |
33 | 34 | SMALL_LAST = regex.compile(r'\b(%s)[%s]?$' % (SMALL, PUNCT), regex.I) |
34 | 35 | SUBPHRASE = regex.compile(r'([:.;?!\-–‒—―][ ])(%s)' % SMALL) |
35 | | -APOS_SECOND = regex.compile(r"^[dol]{1}['‘]{1}[\p{Letter}]+(?:['s]{2})?$", regex.I) |
36 | | -UC_INITIALS = regex.compile(r"^(?:[\p{Uppercase_Letter}]{1}\.{1}|[\p{Uppercase_Letter}]{1}\.{1}[\p{Uppercase_Letter}]{1})+$") |
37 | 36 | MAC_MC = regex.compile(r"^([Mm]c|MC)(\w.+)") |
38 | 37 | MR_MRS_MS_DR = regex.compile(r"^((m((rs?)|s))|Dr)$", regex.I) |
39 | 38 |
|
| 39 | +if REGEX_AVAILABLE: |
| 40 | + INLINE_PERIOD = regex.compile(r'[\p{Letter}][.][\p{Letter}]', regex.I) |
| 41 | + UC_ELSEWHERE = regex.compile(r'[%s]*?[\p{Letter}]+[\p{Uppercase_Letter}]+?' % PUNCT) |
| 42 | + CAPFIRST = regex.compile(r"^[%s]*?([\p{Letter}])" % PUNCT) |
| 43 | + APOS_SECOND = regex.compile(r"^[dol]{1}['‘]{1}[\p{Letter}]+(?:['s]{2})?$", regex.I) |
| 44 | + UC_INITIALS = regex.compile(r"^(?:[\p{Uppercase_Letter}]{1}\.{1}|[\p{Uppercase_Letter}]{1}\.{1}[\p{Uppercase_Letter}]{1})+$") |
| 45 | +else: |
| 46 | + INLINE_PERIOD = regex.compile(r'[\w][.][\w]', regex.I) |
| 47 | + UC_ELSEWHERE = regex.compile(r'[%s]*?[a-zA-Z]+[A-Z]+?' % PUNCT) |
| 48 | + CAPFIRST = regex.compile(r"^[%s]*?([\w])" % PUNCT) |
| 49 | + APOS_SECOND = regex.compile(r"^[dol]['‘][\w]+(?:['s]{2})?$", regex.I) |
| 50 | + UC_INITIALS = regex.compile(r"^(?:[A-Z]\.|[A-Z]\.[A-Z])+$") |
| 51 | + |
| 52 | + |
40 | 53 | class Immutable(object): |
41 | 54 | pass |
42 | 55 |
|
|
0 commit comments