diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-26 17:04:12 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-26 17:04:39 +0100 |
commit | 6ddb09bcb717d87da029af2598a0c1a98b60b0d5 (patch) | |
tree | 967a2e777ce1633852dd62262a52ef88d96b435a /lualib/lua_util.lua | |
parent | d7fc829253b35f2aabc2b229ba94b08bb27288a3 (diff) | |
download | rspamd-6ddb09bcb717d87da029af2598a0c1a98b60b0d5.tar.gz rspamd-6ddb09bcb717d87da029af2598a0c1a98b60b0d5.zip |
[Minor] Add string trimming routine
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 |