Module:Sandbox/sandbox
这是Module:Sandbox(差异)的沙盒。 |
模块文档[创建]
您可能想要创建本Scribunto模块的文档。 编者可以在本模块的沙盒 (编辑 | 差异)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。 本模块的子页面。 |
local p={}
function p.bqreplace( frame )
local new_args = p._getParameters( frame.args, {'source' } )
local source_str = new_args['source'] or ''
if source_str == '' then
return source_str
end
local r1 = {}, r2
local verbose = {}
for i1 in mw.text.gsplit(source_str, "《", true ) do
r2 = {}
table.insert( verbose, "<br/>i1-"..i1 )
for i2 in mw.text.gsplit(i1, "》", true ) do
table.insert( verbose, "<br/>i2-"..i2 )
table.insert( r2, ( mw.ustring.gsub( mw.ustring.gsub( i2, "〈" , "《" ), "〉" , "》" ) ) )
end
table.insert( r1, (table.concat(r2, "〉") ) )
end
return table.concat(r1, "〈") .. table.concat(verbose, "~")
end
--[[
_getParameters() is directly copied from:
https://en.wikipedia.org/w/index.php?title=Module:String&oldid=1181867616
Function code contributors:
https://en.wikipedia.org/w/index.php?title=Module:String&action=history&oldid=1181867616
Helper function that populates the argument list given that user may need to use a mix of
named and unnamed parameters. This is relevant because named parameters are not
identical to unnamed parameters due to string trimming, and when dealing with strings
we sometimes want to either preserve or remove that whitespace depending on the application.
]]
function p._getParameters( frame_args, arg_list )
local new_args = {}
local index = 1
local value
for _, arg in ipairs( arg_list ) do
value = frame_args[arg]
if value == nil then
value = frame_args[index]
index = index + 1
end
new_args[arg] = value
end
return new_args
end
return p