Module:StoryCharaName
Jump to navigation
Jump to search
Documentation for this module may be created at Module:StoryCharaName/doc
local p = {}
function p.main(frame)
local name = frame.args[1] -- grabs the name from invoked arguments
nameTrim = function(input)
local output=string.gsub(string.gsub(input, "^ +", ""), " +$", "") --removes spaces from the beginning & end of the string
if string.find(output, " ") ~=nil then --if there are spaces left in the the string
local spaceLoc=string.find(output, " ") --set the location of the first space as a variable
if string.len(string.sub(output, spaceLoc+1)) <=1 then -- returns the initial input if the length of the string after the space is 1 or less
return output
else --otherwise just returns the string before the first space
return string.sub(output, 0, spaceLoc-1)
end
else --if there are no spaces in the string just returns the initial output
return output
end
end
if string.find(name, "&") ~= nil then --checks if there are ampersands in the string
ampLoc=string.find(name, "&") --saves the location of the first amp location as a variable
if string.find(name, "&", ampLoc+1) == nil then --if there is only one ampersand in the string
return nameTrim(string.sub(name, 0, ampLoc-1)).." & "..nameTrim(string.sub(name, ampLoc+1)) -- return each part of the argument before and after the ampersand through the function
else --if there are multiple ampersands in the string, return "everyone"
return "Everyone"
end
else --if there are no ampersands in the string return the whole string through the function
return nameTrim(name)
end
end
return p