diff options
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r-- | lualib/lua_util.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 755773ea4..2ae4e69b1 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -1,8 +1,8 @@ local exports = {} +local lpeg = require 'lpeg' local split_grammar = {} exports.rspamd_str_split = function(s, sep) - local lpeg = require "lpeg" local gr = split_grammar[sep] if not gr then @@ -16,4 +16,12 @@ exports.rspamd_str_split = function(s, sep) return gr:match(s) end +local space = lpeg.S' \t\n\v\f\r' +local nospace = 1 - space +local ptrim = space^0 * lpeg.C((space^0 * nospace^1)^0) +local match = lpeg.match +exports.rspamd_str_trim = function(s) + return match(ptrim, s) +end + return exports |