Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Ste1la/Names
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!
-- Ste1la Google Code-in, Names of People local p = {} p.getName = function(frame) local name = frame.args.name or "" local format = frame.args.format local givenName = "" local lastName = "" local obtain = 0 if name == "" then return "No name given" end --gets rid of any appendages if name:find("Jr") or name:find("Jr.") or name:find("Sr") or name:find("Sr.") or name:find("II") or name:find("III") then local i, j = name:reverse():find("%S+") name = name:reverse():sub(j+1):reverse() end --check if chinese if obtain == 0 then local exist local chineseList = {"Wang", "Li", "Zhang", "Huang", "Liu", "Chen", "Yang", "Zhao", "Wu", "Zhou", "Xu", "Wen", "Zhu", "Fan", "Zu", "Xu", "Mao", "Sun", "He", "Gao", "Zheng"} for i = 1, #chineseList do if name:find(chineseList[i]) then exist = 1 end end if exist == 1 then lastName = name:match("%a+") local i, j = name:find(lastName) givenName = name:sub(j+2) if givenName:find("%(") then i = givenName:find("%(") givenName = givenName:sub(1, i - 2) end obtain = 1 end end --check if dutch if obtain == 0 then local dutchList = {" van ", " de ", " ter ", " van de ", " van den ", " van der "} for i = 1, #dutchList do if name:find(dutchList[i]) then i, j = name:find(dutchList[i]) lastName = name:sub(i) givenName = name:sub(1, i - 1) obtain = 1 end end --[[if i ~= nil then lastName = name:sub(i) givenName = name:sub(1, i - 2) obtain = 1 elseif name:find("de") then i, j = name:find("de") lastName = name:sub(i) givenName = name:sub(1, i - 2) obtain = 1 elseif name:find("ter") then i, j = name:find("ter") lastName = name:sub(i) givenName = name:sub(1, i - 2) obtain = 1 end]] end --check if spanish if format == "es" or name:find(" y ") then i, j = name:find(" de ") if i ~= nil then lastName = name:sub(j + 1) k, l = lastName:reverse():match("(%S+) (%S+)") if k ~= nil and l ~= nil then if lastName:find("de") == nil then lastName = l:reverse() .. " " .. k:reverse() end end givenName = name:sub(1, i - 1) obtain = 1 elseif name:find(" y ") then i, j, k = name:reverse():match("(%S+) (%S+) (%S+)") lastName = k:reverse() .. " " .. j:reverse() .. " " .. i:reverse() i, j = name:find(lastName) givenName = name:sub(1, i - 2) obtain = 1 else givenName = name:match("%a+") i, j = name:find(givenName) lastName = name:sub(j + 2) obtain = 1 end end --check if thai if format == "th" then givenName = name:match("%S+") i, j = name:find(givenName) lastName = name:sub(j + 2) obtain = 1 end --normal name if obtain == 0 then i, j = name:reverse():find("%S+") lastName = name:reverse():sub(i, j) lastName = lastName:reverse() givenName = name:reverse():sub(j + 2) givenName = givenName:reverse() --[[lastName = name:reverse():match("%S+") lastName = lastName:reverse() i, j = name:find(lastName) givenName = name:sub(1, i-2)]] end out = "''Given'' = " .. givenName .. " -- ''Family'' = " .. lastName return out 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/Ste1la/Names/doc
(
edit
)