author_to_author_sort(): handle multiple suffixes

This commit is contained in:
Kovid Goyal 2011-09-11 10:51:37 -06:00
parent 1411e43920
commit 2cd448687d
2 changed files with 14 additions and 7 deletions

View File

@ -61,7 +61,7 @@ authors_completer_append_separator = False
# selecting 'manage authors', and pressing 'Recalculate all author sort values'. # selecting 'manage authors', and pressing 'Recalculate all author sort values'.
# The author name suffixes are words that are ignored when they occur at the # 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 # 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 # 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 # 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 # identical to the author name. This means that the sort for a string like Acme

View File

@ -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.lower() for x in tweaks['author_name_suffixes']])
suffixes |= set([x+u'.' for x in suffixes]) suffixes |= set([x+u'.' for x in suffixes])
suffix = u''
while True:
if not tokens:
return author
last = tokens[-1].lower() last = tokens[-1].lower()
suffix = None
if last in suffixes: if last in suffixes:
suffix = tokens[-1] suffix = tokens[-1] + ' ' + suffix
tokens = tokens[:-1] tokens = tokens[:-1]
else:
break
suffix = suffix.strip()
if method == u'comma' and u',' in u''.join(tokens): if method == u'comma' and u',' in u''.join(tokens):
return author return author
atokens = tokens[-1:] + tokens[:-1] atokens = tokens[-1:] + tokens[:-1]
num_toks = len(atokens)
if suffix: if suffix:
atokens.append(suffix) atokens.append(suffix)
if method != u'nocomma' and len(atokens) > 1: if method != u'nocomma' and num_toks > 1:
atokens[0] += u',' atokens[0] += u','
return u' '.join(atokens) return u' '.join(atokens)