Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --done LuaU
- -- note: may not work with strings with some escape sequences
- --variables
- local MoonSec = {}
- local StringTks = {
- '\'',
- '"',
- {'[[',']]'}
- }
- --functions
- -- gen
- function Raw(str)return str:gsub('.',{['['] = '%[';[']'] = '%]'})end
- function FlipTable(a)local b={}for c,d in next,a do b[d] = c end return b end
- function GetStringTk(a)for i,v in next,a do v = type(v)=='string'and{v,v}or v a[i]=v end return a end
- -- Moonsec V2 (but it kinda broken rn so lol)
- function GetJunkStrings(sourcecode) -- string:source code
- local Results = {}
- local Check = {}
- for _,strtokens in next,StringTks do
- local begin,end_ = unpack(strtokens)
- --
- local Pattern = '[^'.. Raw(begin) .. '+]#' .. Raw(begin:sub(1,#begin-1)) .. '%b' ..begin:sub(#begin).. end_:sub(1,1) .. Raw(end_:sub(2))
- sourcecode:gsub(Pattern,function(phrase)
- phrase = phrase:sub(3 + #begin,#phrase - #end_)
- if Check[phrase]then return end
- table.insert(Results,phrase)
- Check[phrase] = true
- end)
- end
- return Results
- end
- function CensorJunkStrings(sourcecode,replacementcharacter,IsCompress) -- string:source code, string:replacement character, Boolean-ish: compresses output text, overrides 2nd arg
- replacementcharacter = replacementcharacter and replacementcharacter:sub(1,1)or' '
- local JunkStrings = FlipTable(MoonSec.GetJunkStrings(sourcecode))
- for str in next,JunkStrings do
- local len = #str
- JunkStrings[str] = replacementcharacter:rep(len)
- end
- for _,strtokens in next,StringTks do
- local begin,end_ = unpack(strtokens)
- local Pattern = '[^'.. Raw(begin) .. '+]#' .. Raw(begin:sub(1,#begin-1)) .. '%b' ..begin:sub(#begin).. end_:sub(1,1) .. Raw(end_:sub(2))
- sourcecode = sourcecode:gsub(Pattern,function(found)
- local pre,suf = found:sub(1,2 + #begin), found:sub(#found - #end_ + 1)
- local phrase = found:sub(3 + #begin,#found - #end_)
- return
- IsCompress and found:sub(1,1) .. #phrase or -- check if we compress
- JunkStrings[phrase]and pre .. JunkStrings[phrase] .. suf or -- implement junkstrings if phrase match
- phrase -- anything else
- end)
- end
- return sourcecode
- end
- --assignments
- StringTks = GetStringTk(StringTks)
- MoonSec.GetJunkStrings = GetJunkStrings
- MoonSec.CensorJunkStrings = CensorJunkStrings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement