From: Vsevolod Stakhov Date: Fri, 26 May 2017 16:04:12 +0000 (+0100) Subject: [Minor] Add string trimming routine X-Git-Tag: 1.6.0~130 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6ddb09bcb717d87da029af2598a0c1a98b60b0d5;p=rspamd.git [Minor] Add string trimming routine --- 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