lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> string.escLiteralPattern=function(str) return str:gsub('[-$%%()*+.?[\\%]^]', '%%%0') end`

i would write this as:
`string.escLiteralPattern=function(str) return
str:gsub('[-^$()%%.[%]*+?]', '%%%0') end`
as this preserves the order of the magic chars from the manual, except
for the `'-'`, and the backslash doesnt needed to be escaped if im
right, or at least it isnt a magic character, and it cant have any
side effects, but im not 100% sure :D but the point of not using
`'%p'` is the precise escaping, so ive just thought that its better to
leave out the backslash from the game here...

otherwise embedded zeroes could still fool us, as patterns in 5.1
doesnt like that, but that would require a 2nd run for `gsub()`

so play this:
`string.escLiteralPattern=function(str) return str:gsub('%z',
'%%%z'):gsub('[-^$()%%.[%]*+?]', '%%%0') end`

and this just mentally overwhelmed me (a.m. 2:30 here) for now and im
not sure if im right about the embedded zeroes as well, so dont take
this for sure, but count upon it! :D anyways, if this matters, then it
must be applied to the `'%p'` case as well...


clearance is welcome! :)