mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
author_to_author_sort(): handle multiple suffixes
This commit is contained in:
parent
1411e43920
commit
2cd448687d
@ -61,7 +61,7 @@ authors_completer_append_separator = False
|
||||
# selecting 'manage authors', and pressing 'Recalculate all author sort values'.
|
||||
# The author name suffixes are words that are ignored when they occur at the
|
||||
# end of an author name. The case of the suffix is ignored and trailing
|
||||
# periods are automatically handled.
|
||||
# periods are automatically handled. The same is true for prefixes.
|
||||
# The author name copy words are a set of words which if they occur in an
|
||||
# author name cause the automatically generated author sort string to be
|
||||
# identical to the author name. This means that the sort for a string like Acme
|
||||
|
@ -65,20 +65,27 @@ def author_to_author_sort(author, method=None):
|
||||
suffixes = set([x.lower() for x in tweaks['author_name_suffixes']])
|
||||
suffixes |= set([x+u'.' for x in suffixes])
|
||||
|
||||
last = tokens[-1].lower()
|
||||
suffix = None
|
||||
if last in suffixes:
|
||||
suffix = tokens[-1]
|
||||
tokens = tokens[:-1]
|
||||
suffix = u''
|
||||
while True:
|
||||
if not tokens:
|
||||
return author
|
||||
last = tokens[-1].lower()
|
||||
if last in suffixes:
|
||||
suffix = tokens[-1] + ' ' + suffix
|
||||
tokens = tokens[:-1]
|
||||
else:
|
||||
break
|
||||
suffix = suffix.strip()
|
||||
|
||||
if method == u'comma' and u',' in u''.join(tokens):
|
||||
return author
|
||||
|
||||
atokens = tokens[-1:] + tokens[:-1]
|
||||
num_toks = len(atokens)
|
||||
if suffix:
|
||||
atokens.append(suffix)
|
||||
|
||||
if method != u'nocomma' and len(atokens) > 1:
|
||||
if method != u'nocomma' and num_toks > 1:
|
||||
atokens[0] += u','
|
||||
|
||||
return u' '.join(atokens)
|
||||
|
Loading…
x
Reference in New Issue
Block a user