首页
随机
登录
设置
关于 WinStory Wiki
免责声明
WinStory Wiki
搜索
查看“模块:字符串处理”的源代码
←
模块:字符串处理
因为以下原因,你没有权限 编辑此页:
你请求的操作仅限属于此用户组的用户执行:
用户
你可以查看和复制此页面的源代码。
require('strict') local frame = mw.getCurrentFrame() local p = { } local function explode(s, delimiter) local result = {} local str = s:gsub(delimiter, '|') for match in str:gmatch('[^|]+') do table.insert(result, match) end return result end function p.replace(frame) local s, pattern, repl, n, mode s = frame.args[1] pattern = frame.args[2] repl = frame.args[3] if string.len(frame.args[4]) > 0 then n = tonumber(frame.args[4]) mode = frame.args[5] if mode == "except" then s = s:gsub(pattern, repl) pattern = frame.args[3] repl = frame.args[2] end end local str = s:gsub(pattern, repl, n) return str end function p.dateprocess(frame) local output = '' for i, value in ipairs(explode(frame.args[1], '<br>')) do local date = {value:match('(%d*)(%d%d%d%d%-[%dx]+)')} if date[1] == '' and ({value:match('(%d*)(%d%d%d%d%-%d+%-[%dx]+)')})[2] then date = value:gsub('(%d%d%d%d)%-(%d+)%-([%dx]+)', '%1 年 %2 月 %3 日') elseif date[1] == '' and date[2] then date = value:gsub('(%d%d%d%d)%-(%d+)', '%1 年 %2 月') elseif value:match('^%d%d%d%d') then date = value:gsub('(%d%d%d%d)', '%1 年') else date = value end output = output..date..'<br>' end output = output:gsub('<br>$','') return output end function p.preprocess(frame) for i, value in ipairs(explode(frame.args[1], '<br>')) do local date = {value:match('(%d*)(%d%d%d%d%-%d+)')} if date[1] == '' and date[2] then return 1 elseif value:match('^%d%d%d%d') then return 1 end end return 0 end return p
此页使用的模板:
手动:字符串处理/doc
(
查看源代码
)
返回
模块:字符串处理
。