Module:Module introspection: Difference between revisions
mNo edit summary |
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 | -- 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 | 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) | ||
local blanked = s:gsub("[^\n]", " ") | |||
local | return blanked .. "]]" | ||
return | |||
end) | end) | ||