Editing Module:Case

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 2: Line 2:


langObject = mw.getLanguage('simple')
langObject = mw.getLanguage('simple')
local function has_value (tab, val)
    for index, value in ipairs(tab) do
        if langObject:lc(value) == langObject:lc(val) then
            return true
        end
    end
    return false
end


function p.title_case(frame)
function p.title_case(frame)
Line 18: Line 9:
end
end
split = frame.args.split
split = frame.args.split
if split == "space" then
if frame.args.split == "space" then
split = " "
split = " "
end
end
replace = split
replace = split
if frame.args.replace ~= "" then
if frame.args.replace ~= "nil" then
replace = frame.args.replace
replace = frame.args.replace
end
end
parts = mw.text.split(frame.args.link, split, plain)
parts = mw.text.split(frame.args.link, split, plain)
lower = mw.text.split(frame.args.lower, ",", true)
title = ""
title = ""
for i, part in pairs(parts) do
for _, part in pairs(parts) do
if i > 1 and i < table.getn(parts) and has_value(lower, part) then
  title = title .. langObject:ucfirst(string.lower(part)) .. replace
title = title .. langObject:lc(part) .. replace
else
title = title .. langObject:ucfirst(langObject:lc(part)) .. replace
end
end
end
if table.getn(parts) > 1 then
if table.getn(parts) > 1 then
title = string.sub(title, 0, string.len(title) - string.len(replace))
title = string.sub(title, 0, string.len(title) - 1)
end
if frame.args.nolink == "true" then
return title
end
end
     return "[[" .. frame.args.link .. "|" .. title .. "]]"
     return "[[" .. frame.args.link .. "|" .. title .. "]]"
Line 45: Line 28:


function p.uppercase_first_letter(frame)
function p.uppercase_first_letter(frame)
uc_first_letter = langObject:ucfirst(langObject:lc(frame.args.link))
     return "[[" .. frame.args.link .. "|" .. langObject:ucfirst(string.lower(frame.args.link)) .. "]]"
if frame.args.nolink == "true" then
return uc_first_letter
end
     return "[[" .. frame.args.link .. "|" .. uc_first_letter .. "]]"
end
end


function p.lowercase(frame)
function p.lowercase(frame)
lc = langObject:lc(frame.args.link)
     return "[[" .. frame.args.link .. "|" .. string.lower(frame.args.link) .. "]]"
if frame.args.nolink == "true" then
return lc
end
     return "[[" .. frame.args.link .. "|" .. lc .. "]]"
end
end


return p
return p
Please note that all contributions to Heroes 3 wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)