La documentation pour ce module peut être créée à Module:str2/Documentation
local p = {}
function p.len(frame)
local string = frame.args or ''
return mw.ustring.len(mw.text.trim(string))
end
function p.sub(frame)
local args = frame.args
local string = args or ''
local start = (tonumber(args) or 0) + 1
local length = tonumber(args) 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(args,args,1,true)
if first and first <= last then return first
else return ''
end
end
function p.char(frame)
return mw.ustring.char(frame.args)
end
function p.codepoint(frame)
local str = frame.args or ""
local format = frame.args 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, frame.args, frame.args))
end
function p.gmatch(frame)
local str = ''
for pattern in mw.ustring.gmatch(frame.args, frame.args) do
str = str .. pattern
end
return str
end
function p.sans_balise(frame)
local str = frame.args or ""
str = mw.ustring.gsub(str, "<*>", "")
str = mw.ustring.gsub(str, "'''?", "")
return str
end
function p.format(frame)
local format = frame.args or ""
-- au plus 4 valeurs maintenant
return mw.ustring.format(format, frame.args, frame.args, frame.args, frame.args)
end
function p.liste_de_domaines(frame)
local str = frame.args or ""
local ou = frame.args 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
return p