Module:Xdnum:修订间差异
无编辑摘要 |
无编辑摘要 |
||
(未显示同一用户的20个中间版本) | |||
第2行: | 第2行: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
function | function numtran(input1) | ||
local input = string.gsub(string.gsub(input1,"n","."),"T","0") | |||
local input = string.gsub(string.gsub( | |||
local output = "" | local output = "" | ||
local bj = 0 | local bj = 0 | ||
local aa = {"0","1","2","3","4","5","6","7","8","9"} | local aa = {"0","1","2","3","4","5","6","7","8","9","."} | ||
local bb = {"1","2","3","4","5","6","7","8","9"} | local bb = {"1","2","3","4","5","6","7","8","9"} | ||
local cc = {} | local cc = {} | ||
local dd = {} | local dd = {} | ||
for ii = #aa,1,-1 do | |||
cc[aa[ii]]=1 | |||
cc[ | |||
end | end | ||
for ii, | for ii = #bb,1,-1 do | ||
dd[ | dd[bb[ii]]=1 | ||
end | end | ||
for i = 1,string.len(input) do | for i = 1,string.len(input) do | ||
if ( | if (string.sub(input,i,i)==".") then | ||
bj = 2 | bj = 2 | ||
end | end | ||
if (bj==0 and dd[string.sub(input,i,i)]==1) then | if (bj==0 and dd[string.sub(input,i,i)]==1) then | ||
bj = 1 | bj = 1 | ||
end | |||
if (cc[string.sub(input,i,i)]==nil) then | |||
bj = 0 | |||
end | end | ||
if (bj==1 and string.sub(input,i,i)=="0") then | if (bj==1 and string.sub(input,i,i)=="0") then | ||
第32行: | 第32行: | ||
end | end | ||
end | end | ||
mw.log(output) | |||
return output | |||
end | |||
function module.tran(frame) | |||
local args = getArgs(frame) | |||
local input = tostring(args[1]) | |||
local keya = {"0","1","2","3","4","5","6","7","8","9","T","%."} | |||
local vala = {"","","","","","","","","","","",""} | |||
local output = numtran(input) | |||
for i = 1,12 do | |||
output = string.gsub(output, keya[i], vala[i]) | output = string.gsub(output, keya[i], vala[i]) | ||
end | end |
2021年9月7日 (二) 23:31的最新版本
此模块的文档可以在Module:Xdnum/doc创建
local module = {}
local getArgs = require('Module:Arguments').getArgs
function numtran(input1)
local input = string.gsub(string.gsub(input1,"n","."),"T","0")
local output = ""
local bj = 0
local aa = {"0","1","2","3","4","5","6","7","8","9","."}
local bb = {"1","2","3","4","5","6","7","8","9"}
local cc = {}
local dd = {}
for ii = #aa,1,-1 do
cc[aa[ii]]=1
end
for ii = #bb,1,-1 do
dd[bb[ii]]=1
end
for i = 1,string.len(input) do
if (string.sub(input,i,i)==".") then
bj = 2
end
if (bj==0 and dd[string.sub(input,i,i)]==1) then
bj = 1
end
if (cc[string.sub(input,i,i)]==nil) then
bj = 0
end
if (bj==1 and string.sub(input,i,i)=="0") then
output = output.."T"
else
output = output..string.sub(input,i,i)
end
end
mw.log(output)
return output
end
function module.tran(frame)
local args = getArgs(frame)
local input = tostring(args[1])
local keya = {"0","1","2","3","4","5","6","7","8","9","T","%."}
local vala = {"","","","","","","","","","","",""}
local output = numtran(input)
for i = 1,12 do
output = string.gsub(output, keya[i], vala[i])
end
return output
end
return module