Module:Module introspection: Difference between revisions
bugfix string stripper stripping module names |
No edit summary |
||
| 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) | ||
-- | -- Handle long bracketed strings [[...]] | ||
code_unstripped = code_unstripped:gsub("%[%[(.-)%]%]", function(s) | |||
-- Replace all non-newline characters with spaces | |||
local blanked = s:gsub("[^\n]", " ") | |||
return blanked .. "]]" | |||
end) | |||
-- Handle double-quoted strings not inside require() | |||
code_unstripped = code_unstripped:gsub('(%f[%w]require%s*%(%s*)"(.-)"', function(prefix, s) | code_unstripped = code_unstripped:gsub('(%f[%w]require%s*%(%s*)"(.-)"', function(prefix, s) | ||
return prefix .. '"' .. s .. '"' | return prefix .. '"' .. s .. '"' | ||
end) | end) | ||
code_unstripped = code_unstripped:gsub('"[^"]*"', function(s) | code_unstripped = code_unstripped:gsub('"[^"\n]*"', function(s) | ||
return string.rep(" ", #s) | return string.rep(" ", #s) | ||
end) | end) | ||
-- | -- Handle single-quoted strings not inside require() | ||
code_unstripped = code_unstripped:gsub("(%f[%w]require%s*%(%s*)'(.-)'", function(prefix, s) | code_unstripped = code_unstripped:gsub("(%f[%w]require%s*%(%s*)'(.-)'", function(prefix, s) | ||
return prefix .. "'" .. s .. "'" | return prefix .. "'" .. s .. "'" | ||
end) | end) | ||
code_unstripped = code_unstripped:gsub("'[^']*'", function(s) | code_unstripped = code_unstripped:gsub("'[^'\n]*'", function(s) | ||
return string.rep(" ", #s) | return string.rep(" ", #s) | ||
end) | end) | ||