Regel 56: | Regel 56: | ||
end | end | ||
− | local res = replaceNumbers() | + | local res = p.replaceNumbers( str, padlength ) |
return res | return res | ||
end | end | ||
return p | return p |
Versie van 10 aug 2023 14:37
--[[ Method for replacing numerical sequences in string with zero-padded equivalents ]]-- local p = {} p.padleft = function( str, length, char ) if char == nil then char = '0' end char = '0' res = string.rep( char, length - #str ) .. str return res end --[[ Not currently used ]]-- p.padright = function( str, len, char ) if char == nil then char = '0' end char = '0' res = str .. string.rep( char, len - #str ) return res end p.strip_diacrits = function(wrd) if not wrd or wrd == "" then return "" end for ch in mw.ustring.gmatch(wrd, "%a") do if char_idx[ch] then wrd = wrd:gsub(ch, char_idx[ch]) end end return wrd end p.replaceNumbers = function( str, padlength ) local res = string.gsub( str, "(%d+)", function(d) return p.padleft( d, padlength, '0' ) end ) return res end function p.main( frame ) if frame.args[1] == nil then return "" end str = mw.text.unstrip( frame.args[1] ) if frame.args[2] == nil then padlength = 5 else padlength = mw.text.unstrip( frame.args[2] ) end local res = p.replaceNumbers( str, padlength ) return res end return p