1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
local ReceiverBase = require("core:erm.ReceiverBase")
local VR = ReceiverBase:new()
function VR:new(ERM, v)
assert(v ~= nil, "!!VR requires variable identifier")
return ReceiverBase.new(self, {v=v, ERM=ERM})
end
local match = string.match
local function trim(s)
return match(s,'^()%s*$') and '' or match(s,'^%s*(.*%S)')
end
function VR:H(flagIndex)
local v = trim(self.v)
self.ERM.F[flagIndex] = v ~= ''
end
function VR:U(subString)
self.ERM.F['1'] = string.find(self.v, subString) > 0
end
function VR:M1(startIndex, length)
return string.sub(self.v, startIndex - 1, startIndex - 1 + length)
end
function VR:M2(wordIndex)
local words = string.gmatch(self.v, "[^%s]+")
local i = 0
for w in words do
if i == wordIndex then
return w
end
i = i + 1
end
end
function VR:M3(val, radix)
radix = radix or 10
if(type(val) ~= "number") then
error("The first parameter should be of numeric type")
end
if(type(radix) ~= "number") then
error("The second parameter should be of numeric type. Default value is 10.")
end
if radix == 10 then
return tostring(val)
elseif radix == 16 then
return string.format("%x", val)
else
error("The second parameter value is invalid. Only 10 and 16 radix are supported for now.")
end
end
function VR:M4()
return string.len(self.v)
end
function VR:M5()
local firstPos = string.find(str, "[^%s]+")
return firstPos
end
function VR:M6()
local lastPos = 1 + string.len(self.v) - string.find(string.reverse(self.v), "[^%s]+")
return lastPos
end
return VR
|