View source for Module:String utilities
Jump to navigation
Jump to search
You do not have permission to edit this page, for the following reason:
You can view and copy the source of this page.
local module_name = "string_utilities"
local export = {}
local format_escapes = {
["op"] = "{",
["cl"] = "}",
}
function export.format_fun(str, fun)
return (str:gsub("{(\\?)((\\?)[^{}]*)}", function (p1, name, p2)
if #p1 + #p2 == 1 then
return format_escapes[name] or error(module_name .. ".format: unrecognized escape sequence '{\\" .. name .. "}'")
else
if fun(name) and type(fun(name)) ~= "string" then
error(module_name .. ".format: '" .. name .. "' is a " .. type(fun(name)) .. ", not a string")
end
return fun(name) or error(module_name .. ".format: '" .. name .. "' not found in table")
end
end))
end
000
1:0
Template used on this page:
Return to Module:String utilities.