-- The Main purpose is to convert ROMAN dates to Arabic numerals
-- wjk - Matroc
local p = {}
function p.romantonum( frame )
local RN = { ["M"] = 1000, ["D"] = 500, ["C"] = 100, ["L"] = 50, ["X"] = 10, ["V"] = 5, ["I"] = 1 }
local convert = 0
local x, y = 0
local input = frame.args[1] or "error"
if input == "" then
error("Bad Input Argument! No Data!")
end
input = input:upper()
input = input:match'^%s*(.*%S)' -- trim spaces at both ends
local err = (string.gsub(input,"[MDCLXVI]",""))
if err:len() ~= 0 then
error("Bad Input Argument! only MDCLXVI as characters allowed")
end
local i = 1
local strlen = string.len(input)
while i < strlen do
x, y = RN[ string.sub(input,i,i) ], RN[ string.sub(input,i+1,i+1) ]
if x < y then
convert = convert + ( y - x )
i = i + 2
else
convert = convert + x
i = i + 1
end
end
if i <= strlen then convert = convert + RN[ string.sub(input,i,i) ] end
return convert
end
return p