Playstore.png

Module:Author Names Sorter Chicago 16th

From Religion
Jump to navigation Jump to search

Documentation for this module may be created at Module:Author Names Sorter Chicago 16th/doc

local p = {}
allNames ="";
function p.authors(frame)
  line = frame.args[1]
  for token in string.gmatch(line, "[^%;]+") do
  token = string.gsub(token, "^%s*(.-)%s*$", "%1")
  if allNames == "" then
    if string.match(token, ",") then
      allNames = token
    elseif string.match(token, " ") then
      lastName = string.sub (token,token:match'^.*() ' +1)
      firstName = string.gsub(token, " " .. lastName .."$", "")
      allNames = lastName .. ", " .. firstName
    else
      allNames = token
    end
  else
    if string.match(token, ",") then
       lastName = string.sub (token,0, string.find(token, ",") -1)
       firstName = string.gsub(token, lastName .. ",", "")
       firstName = string.gsub(firstName, "^%s*(.-)%s*$", "%1")
       allNames = allNames .. ", " .. firstName .. " " .. lastName 
    else
      allNames = allNames .. ", " .. token
    end
  end
end
  return allNames
end

return p