regex.lua (imapfilter-2.7.3) | : | regex.lua (imapfilter-2.7.4) | ||
---|---|---|---|---|
-- A simple wrapper for PCRE that uses a cache for compiled expressions. | -- A simple wrapper for PCRE that uses a cache for compiled expressions. | |||
_regex_cache = {} | _regex_cache = {} | |||
_regex_cache.mt = {} | _regex_cache.mt = {} | |||
setmetatable(_regex_cache, _regex_cache.mt) | setmetatable(_regex_cache, _regex_cache.mt) | |||
_regex_cache.mt.__index = function (self, key) | _regex_cache.mt.__index = function (self, key) | |||
local r, compiled = ifre.compile(pattern) | local r, compiled = ifre.compile(key) | |||
if not r then return end | if not r then return end | |||
self[key] = compiled | self[key] = compiled | |||
return compiled | return compiled | |||
end | end | |||
function regex_search(pattern, subject) | function regex_search(pattern, subject) | |||
_check_required(pattern, 'string') | _check_required(pattern, 'string') | |||
_check_required(subject, 'string') | _check_required(subject, 'string') | |||
local compiled = _regex_cache[pattern] | local compiled = _regex_cache[pattern] | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added |