local p =
function p.surname(frame) local fullname = frame.args[1] --Pull off any generational suffix suffix1_index = mw.ustring.find(fullname, ',? [JS]n?r%.?$') suffix2_index = mw.ustring.find(fullname, ' [IVX]+$') if type(suffix1_index) ~= 'nil' then suffix = mw.ustring.sub(fullname, suffix1_index) nosuffix = mw.ustring.sub(fullname, 1, suffix1_index-1) elseif type(suffix2_index) ~= 'nil' then suffix = mw.ustring.sub(fullname, suffix2_index) nosuffix = mw.ustring.sub(fullname, 1, suffix2_index-1) else suffix = nosuffix = fullname end
----Pull off last word-- lastword_index = mw.ustring.find(nosuffix, '[^]%S+$') if type(mw.ustring.find(nosuffix, ' %S+$'))
lastword = mw.ustring.sub(nosuffix, lastword_index) nolastword = mw.ustring.sub(nosuffix, 1, lastword_index-1)
--Pull off second to last word-- secondtolastword_index = mw.ustring.find(nolastword, '[^]%S+$') secondtolastword_index = mw.ustring.find(nolastword, ' %S+$') or mw.ustring.find(nolastword, '^%S+$') secondtolastword = mw.ustring.sub(nolastword, secondtolastword_index) nosecondtolastword = mw.ustring.sub(nolastword, 1, secondtolastword_index-1) secondtolastword_lower = mw.ustring.lower(secondtolastword)
prefixes = .. .. .. local surname, givenname for prefix in prefixes do if secondtolastword_lower
'der' or secondtolastword_lower
'y') or (thirdtolastword_lower
'der') then surname = thirdtolastword .. ' ' .. secondtolastword .. ' ' .. lastword givenname = nothirdtolastword end else surname = lastword givenname = nolastword end sortname = surname .. ', ' .. givenname .. ' ' .. suffix return sortname--
return nosuffixendreturn p