-- CFB schedule table conversion
-- {{subst:#invoke:CFB schedule/convert|table|...}}
local p = {}
local function parseHeader(s)
return '{' .. s .. '}'
end
local function parseFooter(s)
return '{' .. s .. '}'
end
local function parseEntry(s)
s = '♦MARK♦' .. s
k = 0
while mw.ustring.find(s, '♦MARK♦') and (k < 100) do
k = k + 1
s=mw.ustring.gsub(s,'(♦MARK♦)%s*%|%s*([^%|{}%[%]=]*=)', '♦%2%1')
s=mw.ustring.gsub(s,'(♦MARK♦)([^%|{}%[%]=]*)', '%2%1')
s=mw.ustring.gsub(s,'(♦MARK♦)(%{%{[^%{%}]*%}%})', '%2%1')
s=mw.ustring.gsub(s,'(♦MARK♦)(%[%[[^%[%]]*%]%])', '%2%1')
s=mw.ustring.gsub(s,'(♦MARK♦)(%[[^%[%]]*%])', '%2%1')
s=mw.ustring.gsub(s,'♦MARK♦$', '')
end
return '{' .. s .. '}'
end
function p.table(frame)
local res = ''
for t in mw.text.gsplit(frame.args[1] or '', '{{[_%s]*CFB[_%s]*Schedule[_%s]*') do
local s = t:match( '^%s*(.-)%s*$' )
if mw.ustring.sub(s,-2) == '}}' then
s = mw.ustring.sub(s,1,-3)
if mw.ustring.sub(s,1,5) == 'Entry' then
res = res .. parseEntry(mw.ustring.sub(s,6))
elseif mw.ustring.sub(s,1,5) == 'Start' then
res = res .. parseHeader(mw.ustring.sub(s,6))
elseif mw.ustring.sub(s,1,3) == 'End' then
res = res .. parseFooter(mw.ustring.sub(s,4))
else
res = res .. t
end
else
res = res .. t
end
end
return res
end
return p