Better handling of empty prefix list

This commit is contained in:
Kovid Goyal 2022-02-04 16:41:08 +05:30
parent b4e6ae8c2b
commit ca0a977b09
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -163,12 +163,15 @@ def get_title_sort_pat(lang=None):
ans = frozenset(ans) if ans is not None else frozenset(data['eng'])
except Exception:
ans = frozenset((r'A\s+', r'The\s+', r'An\s+'))
if ans:
ans = '|'.join(ans)
ans = '^(%s)'%ans
try:
ans = re.compile(ans, re.IGNORECASE)
except:
ans = re.compile(r'^(A|The|An)\s+', re.IGNORECASE)
else:
ans = re.compile('^$') # matches only the empty string
_title_pats[lang] = ans
return ans