-- smsingh Lua Task 8, Names of Peoplelocal p = p.formatname = function (frame) fullname = frame.args.fullname nameformat = frame.args.nameformat lastname = "" givenname = ""-- Dutch names dutchnames = function dutchlastname(name) for i = 1, #dutchnames do if string.match(name, dutchnames[i]) then lastnameindex = string.find(name, dutchnames[i]) lastname = string.sub(name, lastnameindex) name = string.gsub(name, dutchnames[i], "") break end end return lastname end -- Spanish names function spanishlastname(name) if string.match(name, " y ") then lastname = string.gsub(name, " y ", " ") else lastname = fullname end if string.match(string.reverse(string.match(string.reverse(lastname), "[%S]+ [%S]+")), "de ") then lastname = string.reverse(string.match(string.reverse(lastname), "[%S]+ [%S]+ [%S]+")) else lastname = string.reverse(string.match(string.reverse(lastname), "[%S]+ [%S]+")) end return lastname end -- Portugeuse names portuguesenames = function portugueselastname(name) for i = 1, #portuguesenames do if string.match(name, portuguesenames[i]) then lastnameindex = string.find(name, portuguesenames[i]) lastname = string.sub(name, lastnameindex) name = string.gsub(name, portuguesenames[i], "") break end end return lastname end -- juniors, seniors, and roman numerals fullname = string.gsub(fullname, " Jr.", "") fullname = string.gsub(fullname, " Sr.", "") fullname = string.gsub(fullname, " Jr", "") fullname = string.gsub(fullname, " Sr", "") if not (string.match(fullname, " II")
"es" then spanishlastname(fullname) elseif nameformat
"" then lastname = "" else lastname = string.match(fullname, "(%a+)") end elseif (not (dutchlastname(fullname)
"") then portugueselastname(fullname) elseif fullname
"" then return "No name given" else lastname = string.reverse(string.match(string.reverse(fullname), "[%S-]+")) end if lastname