Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Swpb/surname-sort
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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+$')) == 'nil' then lastword_index = mw.ustring.find(nosuffix, '^%S+$') else lastword_index = mw.ustring.find(nosuffix, ' %S+$') end 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 = {'a', 'ab', 'af', 'av', 'ap', 'abu', 'al', 'ālam', 'alam', 'bar', 'bath', 'bat', 'bean', 'ben', 'bet', 'bin', 'bint', 'da', 'das', 'de', 'degli', 'del', 'dele', 'della'} .. { 'der', 'di', 'dos', 'du', 'e', 'el', 'fetch', 'vetch', 'fitz', 'i', 'ibn', 'kil', 'gil', 'la', 'le', 'lu', 'm\'', 'mac', 'mc', 'mck', 'mhic', 'mic', 'mag', 'mala', 'maol', 'mug'} .. {'na', 'neder', 'ní', 'ni', 'nic', 'nig', 'nin', 'nord', 'norr', 'ny', 'ó', 'o', 'öfver', 'ofver', 'ost', 'öst', 'öster', 'øst', 'över', 'over', 'öz', 'pour', 'saint', 'san'} .. {'ste', 'stor', 'söder', 'soder', 'sønder', 'sonder', 'ter', 'tre', 'ua', 'uí', 'ui\'', 'ui', 'van', 'väst', 'vast', 'väster', 'vaster', 'vest', 'von', 'woj', 'zu'} local surname, givenname for prefix in prefixes do if secondtolastword_lower == prefix then surname = secondtolastword .. ' ' .. lastword givenname = nosecondtolastword end end if secondtolastword_lower == 'der' or secondtolastword_lower == 'y' then -- thirdtolastword_index = mw.ustring.find(nosecondtolastword, '[ ^]%S+$') thirdtolastword_index = mw.ustring.find(nosecondtolastword, ' %S+$') or mw.ustring.find(nosecondtolastword, '^%S+$') thirdtolastwod = mw.ustring.sub(nosecondtolastword, thirdtolastword_index) nothirdtolastword = mw.ustring.sub(nosecondtolastword, 1, thirdtolastword_index-1) thirdtolastword_lower = mw.ustring.lower(thirdtolastword) if (secondtolastword_lower == 'y') or (thirdtolastword_lower == 'van' and secondtolastword_lower == 'der') then surname = thirdtolastword .. ' ' .. secondtolastword .. ' ' .. lastword givenname = nothirdtolastword end else surname = lastword givenname = nolastword end sortname = surname .. ', ' .. givenname .. ' ' .. suffix return sortname --]] return nosuffix end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Swpb/surname-sort/doc
(
edit
)