![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
This module directly imports all functions from the
mw.ustring
library. Documentation for each function can be found there.
The module takes an indefinite number of arguments. All arguments are coerced as number type if possible. If you wish for something to remain a string, you can escape it with \
, which in turn can be escaped by itself.
You can also wrap results in tags. All non-number indexed arguments will be passed to
frame:extensionTag
1 Usage[]
{{#invoke:Ustring|function_name|arg1|arg2|...}}
is equivalent to mw.ustring.function_name
( arg1, arg2, ... )
1.1 Example using mw.ustring.sub[]
{{#invoke:Ustring|sub|abcde|2|4}}
produces:
bcd
1.2 Example using mw.ustring.gsub[]
{{#invoke:Ustring|gsub|1234|23|}}
produces:
14
1.3 Example using mw.ustring.match[]
{{#invoke:Ustring|match|abcde|(c%w)}}
produces:
cd
1.4 Example using tag arguments[]
{{#invoke:Ustring|sub|{{Module:Ustring}}|274|548 |tag=pre|style=background-color:#edd}}
produces:
if frame.args.tag then local tag = {name = frame.args.tag, content = mw.ustring[k](unpack(args)), args = {}} for x, y in pairs(frame.args) do if type(x)~='number' and x~='tag' and not tag[x] then tag.args[x] = y end end return frame:extensionTag(tag) end
Note that:
<pre style=background-color:#edd>{{#invoke:Ustring|sub|{{Module:Ustring}}|274|548}}</pre>
produces:
{{#invoke:Ustring|sub|{{Module:Ustring}}|274|548}}
p = {}
for k, v in pairs(mw.ustring) do
p[k] = function(frame)
local args = {}
for _, v in ipairs(frame.args) do
table.insert(args, tonumber(v) or string.gsub(string.gsub(string.gsub(v,"\\\\",string.char(127,4,127,2)), "\\", ""), string.char(127,4,127,2), "\\"))
end
if frame.args.tag then
local tag = {name = frame.args.tag, content = mw.ustring[k](unpack(args)), args = {}}
for x, y in pairs(frame.args) do
if type(x)~='number' and x~='tag' and not tag[x] then tag.args[x] = y end
end
return frame:extensionTag(tag)
end
return (mw.ustring[k](unpack(args)))
end
end
return p