Module:Module introspection: Difference between revisions

Ganaram inukshuk (talk | contribs)
mNo edit summary
Ganaram inukshuk (talk | contribs)
bugfix string stripper stripping module names
Line 71: Line 71:
-- Blanks strings while preserving line numbers
-- Blanks strings while preserving line numbers
function p.strip_strings(code_unstripped)
function p.strip_strings(code_unstripped)
-- Blank double-quoted strings
-- Blank double-quoted strings not inside require()
code_unstripped = code_unstripped:gsub('"(.-)"', function(s)
code_unstripped = code_unstripped:gsub('(%f[%w]require%s*%(%s*)"(.-)"', function(prefix, s)
return string.rep(" ", #s + 2) -- +2 for the quotes
-- Keep the module name intact
return prefix .. '"' .. s .. '"'
end)
code_unstripped = code_unstripped:gsub('"[^"]*"', function(s)
return string.rep(" ", #s)
end)
end)


-- Blank single-quoted strings
-- Blank single-quoted strings not inside require()
code_unstripped = code_unstripped:gsub("'(.-)'", function(s)
code_unstripped = code_unstripped:gsub("(%f[%w]require%s*%(%s*)'(.-)'", function(prefix, s)
return string.rep(" ", #s + 2)
return prefix .. "'" .. s .. "'"
end)
code_unstripped = code_unstripped:gsub("'[^']*'", function(s)
return string.rep(" ", #s)
end)
end)


-- Blank long bracketed strings [[...]]
-- Blank long bracketed strings [[...]] normally
code_unstripped = code_unstripped:gsub("%[%[(.-)%]%]", function(s)
code_unstripped = code_unstripped:gsub("%[%[(.-)%]%]", function(s)
-- Preserve line breaks
local blanked = s:gsub("[^\n]", " ")
local blanks = s:gsub(".", " ")
return blanked .. "]]"
local newlines = s:gsub("[^\n]", " ")
return blanks .. "]" .. "]"
end)
end)