Module:Sandbox/Ste1la/Names Explained

-- Ste1la Google Code-in, Names of Peoplelocal 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 = 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 = 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 -- 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 -- end out = "Given = " .. givenName .. " -- Family = " .. lastName return outend

return p