Amṣada:str
Apparence
La documentation pour ce module peut être créée à Amṣada:str/doc
local p = {}
function p.len(frame)
local string = frame.args[1] or ''
return mw.ustring.len(mw.text.trim(string))
end
function p.sub(frame)
local args = frame.args
local string = args[1] or ''
local start = (tonumber(args[2]) or 0) + 1
local length = tonumber(args[3]) or 0
if length <= 0 then return ''
else
return mw.ustring.sub(mw.text.trim(string), start, start + length - 1)
end
end
function p.find(frame)
local args = frame.args
local first, last = mw.ustring.find(mw.text.trim(args[1]), args[2], 1, true)
if first and first <= last then return first
else return ''
end
end
function p.char(frame)
return mw.ustring.char(frame.args[1])
end
function p.codepoint(frame)
local str = frame.args[1] or ""
local format = frame.args["format"] or "%d"
str = mw.ustring.gsub(str, "(.)",
function (caractere)
return mw.ustring.format(format, mw.ustring.codepoint(caractere))
end)
return str
end
function p.gsub(frame)
return (mw.ustring.gsub(frame.args[1], frame.args[2], frame.args[3]))
end
function p.gmatch(frame)
local str = ''
for pattern in mw.ustring.gmatch(frame.args[1], frame.args[2]) do
str = str .. pattern
end
return str
end
function p.ulac_tagmirt(frame)
local str = frame.args[1] or ""
str = mw.ustring.gsub(str, "<[^>]*>", "")
str = mw.ustring.gsub(str, "'''?", "")
return str
end
function p.format(frame)
local format = frame.args[1] or ""
-- au plus 4 valeurs maintenant
return mw.ustring.format(format, frame.args[2], frame.args[3], frame.args[4], frame.args[5])
end
function p.liste_de_domaines(frame)
local str = frame.args[1] or ""
local ou = frame.args["ou"] or ""
str = mw.ustring.gsub(str, "%)''([^']*)$", "%1")
str = mw.ustring.gsub(str, "%)''", ", ")
str = mw.ustring.gsub(str, "''%(", "")
if ou ~= "" then
str = mw.ustring.gsub(str, ", ([^,]*)$", " ou %1")
end
return "''(" .. str .. ")''"
end
function p.ucfirstall(frame)
local str = frame.args[1] or ""
str = mw.ustring.gsub(str, "^%S", mw.ustring.upper)
str = mw.ustring.gsub(str, "%s%S", mw.ustring.upper)
return str
end
function p.supprimer_p(frame)
local str = frame.args[1] or ""
str = mw.ustring.gsub(str, "^</?p>\n?", " \n")
str = mw.ustring.gsub(str, "</?p>", "<br />")
return str
end
return p