diff options
Diffstat (limited to 'rules')
-rw-r--r-- | rules/global_functions.lua | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/rules/global_functions.lua b/rules/global_functions.lua index e3a167a07..3a60e5812 100644 --- a/rules/global_functions.lua +++ b/rules/global_functions.lua @@ -178,12 +178,18 @@ function rspamd_redis_make_request(task, redis_params, key, is_write, callback, return ret,conn,addr end +local split_grammar function rspamd_str_split(s, sep) local lpeg = require "lpeg" - sep = lpeg.P(sep) - local elem = lpeg.C((1 - sep)^0) - local p = lpeg.Ct(elem * (sep * elem)^0) -- make a table capture - return lpeg.match(p, s) + + if not split_grammar then + sep = lpeg.P(sep) + local elem = lpeg.C((1 - sep)^0) + local p = lpeg.Ct(elem * (sep * elem)^0) + split_grammar = p + end + + return lpeg.match(split_grammar, s) end -- Metafunctions |