mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
ERM VR:M,VR:U
This commit is contained in:
@@ -18,5 +18,61 @@ function VR:H(flagIndex)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user