Module:Smyth/sandbox: Difference between revisions

Content deleted Content added
Theoretically, this can't happen either - gmatch will give an empty string for postscripts and separators if the first capture group matches but the second/third ones match empty strings. postscripts[1] would be nil if the line 46 else branch was reached, but we can just set postscripts[1] = "" there. Also, making `n` a local variable, and moving it a bit further up
sync with live module
 
Line 37:
local part = frame.args[2]
if sectionParameter then
local n = 1
if mw.ustring.find(sectionParameter, "[^%d%s]") then
local n = 1
for number, postscript, separator in mw.ustring.gmatch(sectionParameter, "(%d+ ?%u?)(%.?[%l%d]?)(%p?[^%d]*)") do
sections[n], postscripts[n], separators[n] = number, postscript, separator
if sections[n] == "" or sections[n] == nil then
break
end
n = n + 1
end
else
sections[1], postscripts[1], separators[1] = mw.ustring.match(sectionParameter, "(%d+)"), "", ""
end
else
error("SmythSection wants input in the first parameter")
end
if #sections == 0nil then
error("No numbers in the text provided to SmythSection")
elseif sections[2] == "" or sections[2] == nil then
sign = "§"
else
sign = "§§"
end
for i = 1, #sections do
if sections[i] == "" or sections[i] == nil then -- Does gmatch return nil or an empty string when it finds no match?
output = output .. "[" .. Smyth(sections[i]).url .. " "
break
if i == 1 then
else
output = output .. sign .. " "
if not postscripts[i] then postscripts[i] = "" end
if not separators[i] then separators[i] = "" end
output = output .. "[" .. Smyth(sections[i]).url .. " "
if i == 1 then
output = output .. sign .. " "
end
output = output .. sections[i] .. postscripts[i] .. "]" .. separators[i]
end
output = output .. sections[i] .. postscripts[i] .. "]" .. separators[i]
end
return output