Module:EncounterTable: Difference between revisions

542 bytes added ,  18:13, 12 November 2019
no edit summary
mNo edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
--a lot taken from lol gamepedia
function p.gsplit( text, pattern, plain )
if not pattern then pattern = '%s*,%s*' end
local s, l = 1, text:len()
return function ()
if s then
local e, n = text:find( pattern, s, plain )
local ret
if not e then
ret = text:sub( s )
s = nil
elseif n < e then
-- Empty separator!
ret = text:sub( s, e )
if e < l then
s = e + 1
else
s = nil
end
else
ret = e > s and text:sub( s, e - 1 ) or ''
s = n + 1
end
return ret
end
end, nil, nil
end


function p.split(text, pattern, plain)
function p.split(text, pattern, plain)
Line 6: Line 34:
end
end
local ret = {}
local ret = {}
for m in p.gsplit(text, pattern, plain) do
for m in gmatch(text, pattern, plain) do
ret[#ret+1] = m
ret[#ret+1] = m
end
end