Ad placeholder

Module:ParseList: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Add drow and dragonborn subraces)
No edit summary
Line 23: Line 23:
local specialPlurals = {
local specialPlurals = {
-- Weapons
-- Weapons
Quarterstaff = "Quarterstaves",
quarterstaff = "quarterstaves",
Staff = "Staves",
Staff = "Staves",
staff = "staves",
staff = "staves",
Line 36: Line 34:
Drow = "Drow",
Drow = "Drow",
drow = "drow",
drow = "drow",
["Lolth-Sworn Drow"] = "Lolth-Sworn Drow",
["Lolth-sworn drow"] = "Lolth-sworn drow",
["Seldarine Drow"] = "Seldarine Drow",
["Seldarine drow"] = "Seldarine drow",
Dragonborn = "Dragonborn",
Dragonborn = "Dragonborn",
dragonborn = "dragonborn",
dragonborn = "dragonborn",
["Black Dragonborn"] = "Black Dragonborn",
["black dragonborn"] = "black dragonborn",
["Blue Dragonborn"] = "Blue Dragonborn",
["blue dragonborn"] = "blue dragonborn",
["Brass Dragonborn"] = "Brass Dragonborn",
["brass dragonborn"] = "brass dragonborn",
["Bronze Dragonborn"] = "Bronze Dragonborn",
["bronze dragonborn"] = "bronze dragonborn",
["Copper Dragonborn"] = "Copper Dragonborn",
["copper dragonborn"] = "copper dragonborn",
["Gold Dragonborn"] = "Gold Dragonborn",
["gold dragonborn"] = "gold dragonborn",
["Green Dragonborn"] = "Green Dragonborn",
["green dragonborn"] = "green dragonborn",
["Red Dragonborn"] = "Red Dragonborn",
["red dragonborn"] = "red dragonborn",
["Silver Dragonborn"] = "Silver Dragonborn",
["silver dragonborn"] = "silver dragonborn",
["White Dragonborn"] = "White Dragonborn",
["white dragonborn"] = "white dragonborn",
-- Creature types
-- Creature types
Fey = "Fey",
Fey = "Fey",
Line 69: Line 43:
}
}


-- Checks if str is equal to or ends in one of the keys in specialPlurals.
-- Returns the pluralized version if so, otherwise nil.
local function findSpecialPlural(str)
for singular, plural in pairs(specialPlurals) do
if str == singular then
return plural
end
local len = #singular
local suffix = str:sub(-len, -1)
if (suffix == singular) then
return str:sub(1, -len - 1) .. plural
end
end
end
-- Checks if str is equal to or ends in one of the values in specialPlurals.
-- Returns the singular version if so, otherwise nil.
local function findSpecialSingular(str)
for singular, plural in pairs(specialPlurals) do
if str == plural then
return singular
end
local len = #plural
local suffix = str:sub(-len, -1)
if suffix == plural then
return str:sub(1, -len - 1) .. singular
end
end
end
-- Checks for a special pluralization first, then implements these rules:
-- ...f -> ...ves
-- ...y -> ...ies
-- ...s -> ...ses
-- ...ch -> ...ches
-- ...sh -> ...shes
-- ... -> ...s
local function makePlural(str)
local function makePlural(str)
local sp = specialPlurals[str]
local sp = findSpecialPlural(str)
if sp then
if sp then
return sp
return sp
end
end
local lastLetter = str:sub(-1)
local last1 = str:sub(-1)
if lastLetter == "y" then
if last1 == "f" then
return str:sub(1, -2) .. "ves"
elseif last1 == "y" then
return str:sub(1, -2) .. "ies"
return str:sub(1, -2) .. "ies"
elseif lastLetter == "f" then
elseif last1 == "s" then
return str:sub(1, -2) .. "ves"
return str .. "es"
end
local last2 = str:sub(-2)
if last2 == "ch" or last2 == "sh" then
return str .. "es"
end
end
return str .. "s"
return str .. "s"
end
end


-- Checks for a special singularization first, then implements these rules:
-- ...ves -> ...f
-- ...ies -> ...y
-- ...ses -> ...s
-- ...ches -> ...ch
-- ...shes -> ...sh
-- ...s -> ...
-- ... -> ...
local function makeSingular(str)
local function makeSingular(str)
local special
local special = findSpecialSingular(str)
for k, v in pairs(specialPlurals) do
if v == str then
special = k
break
end
end
if special then
if special then
return special
return special
end
end
if str:sub(-3) == "ies" then
local last3 = str:sub(-3)
if last3 == "ves" then
return str:sub(1, -4) .. "f"
elseif last3 == "ies" then
return str:sub(1, -4) .. "y"
return str:sub(1, -4) .. "y"
elseif last3 == "ses" then
return str:sub(1, -3)
end
local last4 = str:sub(-4)
if last4 == "ches" or last4 == "shes" then
return str:sub(1, -3)
end
if str:sub(-1) == "s" then
return str:sub(1, -2)
end
end
return str:sub(1, -2)
return str
end
end


-- Applies the singular/plural transform and linkification
local function processElement(str)
local function processElement(str)
local modified = str
local original = str
if makeElementsPlural then
if makeElementsPlural then
modified = makePlural(str)
str = makePlural(str)
elseif makeElementsSingular then
elseif makeElementsSingular then
modified = makeSingular(str)
str = makeSingular(str)
end
end
if makeElementsLinks then
if makeElementsLinks then
return "[[" .. str .. "|" .. modified .. "]]"
return "[[" .. original .. "|" .. str .. "]]"
else
return modified
end
end
return str
end
end


Navigation menu