全站通知:
模块:SplitFormat
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:SplitFormat/doc创建
local p = {}
function p.split(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local sep0 = (args.sep0 or ",")
local sep1 = (args.sep1 or ",")
local fmt = (args.fmt or "$")
local res = {}
local func = function(w)
local w = string.gsub(w, "^%s*(.+)%s*$", "%1")
w = string.gsub(fmt, "%$", w)
table.insert(res, w)
end
local expand_tem = function()
if args.template == "" then
for i = 1, #res do res[i] = frame:expandTemplate{ title = res[i], args = {} } end
elseif args.template then
for i = 1, #res do res[i] = frame:expandTemplate{ title = args.template, args = { res[i] } } end
end
end
string.gsub(args.str, string.format("([^%s]+)", sep0), func)
expand_tem()
return table.concat(res, sep1)
end
function p.apply_template(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local res = {}
local func = function(w)
local w = string.gsub(w, "^%s*(.+)%s*$", "%1")
if string.find(w, "=") ~= nil then
local eq = string.find(w, "=")
res[string.sub(w, 1, eq - 1)] = string.sub(w, eq + 1)
end
end
string.gsub(args.params, string.format("([^%s]+)", "|"), func)
return frame:expandTemplate{ title = args.template, args = res }
end
function p.enhance_icons(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local res = {}
local func = function(w)
local i, t
w = string.gsub(w, "^%s*(.+)%s*$", "%1")
i, t = string.match(w, '^(%d+)(%D+)$')
if t == "宝具" or t == "技能" then
table.insert(res, {i, t})
end
end
string.gsub(args.str, "([^,]+)", func)
local size_px = (#res > 7) and 46 or 60
res_str = ""
for i = #res, 1, -1 do res_str = res_str .. frame:expandTemplate{ title = "从者强化图标", args = { res[i][1], res[i][2], ["size"] = size_px } } end
return res_str
end
function p.del_smw(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local res = (args.str or "")
res = string.gsub(res, "%[%[SMW::on%]%]", "")
res = string.gsub(res, "%[%[SMW::off%]%]", "")
return res
end
function p.str_decode(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
return mw.text.decode(args.str, true)
end
function p.apply_template2(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local sep0 = (args.sep0 or ",")
local sep1 = (args.sep1 or ",")
local sep2 = (args.sep2 or ",")
local other = {}
local func = function(w)
local w = string.gsub(w, "^%s*(.+)%s*$", "%1")
if string.find(w, "=") ~= nil then
local eq = string.find(w, "=")
other[string.sub(w, 1, eq - 1)] = string.sub(w, eq + 1)
end
end
local res={}
local sdebug=''
for i,v in ipairs(mw.text.split(args.str,sep0,true)) do
other={}
string.gsub(args.other, string.format("([^%s]+)", sep1), func)
local temp ={}
if string.find(v,'=')~=nil then
temp = other
string.gsub(v, string.format("([^%s]+)", sep1), func)
else
temp = mw.text.split(v,sep1,true)
end
for k, v in pairs( other ) do
temp[k] = v
end
table.insert(res,frame:expandTemplate{title=args.template,args=temp})
end
return table.concat(res,sep2)
end
--这个函数用于在set前将html tag屏蔽
function p.killHtml(frame)
local args=(frame==mw.getCurrentFrame()and frame.args)or frame
local str=args.str
str=string.gsub(str,'<','<');
str=string.gsub(str,'>','>');
str=string.gsub(str,'"','"');
str=string.gsub(str,"'",''');
return str
end
--替换参数
function p.replace(frame)
local args=(frame==mw.getCurrentFrame()and frame.args)or frame
local str=args.str
local rep=args.rep
str=string.gsub(str,rep,'');
return str
end
return p