Module:Func
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Func/doc
local func = {}
function func.decodeHTML(itemName)
itemName = itemName:gsub("'", "'")
itemName = itemName:gsub("'", "'")
itemName = itemName:gsub("&", "&")
return itemName
end
function func.encodeName(itemName)
local decoded = func.decodeHTML(itemName)
local encodedItemName = decoded:gsub("'", "''")
return encodedItemName
end
function func.removeEncoding(itemName)
local decoded = func.decodeHTML(itemName)
local removedEncodingName = decoded:gsub("'", "")
return removedEncodingName
end
function func.escape(frame)
local str = frame.args[1]
str = str:gsub("!", "") -- Remove exclamation marks
str = str:gsub("'", "") -- Remove apostrophes
str = str:gsub("%.", "") -- Remove periods (dot)
local exceptions = {
["of"] = true,
["the"] = true,
["by"] = true
}
-- Function to capitalize the first letter of each word except exceptions
local function capitalizeFirstLetter(word)
local lower_word = word:lower()
if exceptions[lower_word] then
return lower_word
else
return word:sub(1, 1):upper() .. word:sub(2):lower()
end
end
-- Capitalize the first letter of each word except exceptions
str = str:gsub("(%a[%w]*)", capitalizeFirstLetter)
-- Always capitalize the first word in the string
str = str:gsub("^%l", string.upper)
return str
end
return func