diff options
author | Andrew Lewis <nerf@judo.za.org> | 2017-05-23 12:37:43 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2017-05-23 12:37:43 +0200 |
commit | f859b29631cca0986f3d7423a50c224a28a9404e (patch) | |
tree | 13002e3c79f8b375890b5945821079524dd56637 /lualib/lua_util.lua | |
parent | 89515c1da8691fd9c7c4d913324a49be50512cc1 (diff) | |
download | rspamd-f859b29631cca0986f3d7423a50c224a28a9404e.tar.gz rspamd-f859b29631cca0986f3d7423a50c224a28a9404e.zip |
[Minor] Split global functions into libraries
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r-- | lualib/lua_util.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua new file mode 100644 index 000000000..755773ea4 --- /dev/null +++ b/lualib/lua_util.lua @@ -0,0 +1,19 @@ +local exports = {} + +local split_grammar = {} +exports.rspamd_str_split = function(s, sep) + local lpeg = require "lpeg" + local gr = split_grammar[sep] + + if not gr then + local _sep = lpeg.P(sep) + local elem = lpeg.C((1 - _sep)^0) + local p = lpeg.Ct(elem * (_sep * elem)^0) + gr = p + split_grammar[sep] = gr + end + + return gr:match(s) +end + +return exports |