aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_util.lua
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2017-06-10 15:45:29 +0200
committerAndrew Lewis <nerf@judo.za.org>2017-06-10 15:45:29 +0200
commitc30cfcb21a5d1b2fa14944ff3633198a95ea3c2d (patch)
treea947837bbd92ed3bdf4a22b54dd6b492e9500246 /lualib/lua_util.lua
parentcd0cc6187ed4b153e3506bbf79d28aa760a85f4a (diff)
downloadrspamd-c30cfcb21a5d1b2fa14944ff3633198a95ea3c2d.tar.gz
rspamd-c30cfcb21a5d1b2fa14944ff3633198a95ea3c2d.zip
[Feature] Bayes expiry plugin
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r--lualib/lua_util.lua10
1 files changed, 10 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 0a824dca1..1f53d51ed 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -30,4 +30,14 @@ exports.round = function(num, numDecimalPlaces)
return math.floor(num * mult) / mult
end
+exports.template = function(tmpl, keys)
+ local var_lit = lpeg.P { lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09") + "_" }
+ local var = lpeg.P { (lpeg.P("$") / "") * ((var_lit^1) / keys) }
+ local var_braced = lpeg.P { (lpeg.P("${") / "") * ((var_lit^1) / keys) * (lpeg.P("}") / "") }
+
+ local template_grammar = lpeg.Cs((var + var_braced + 1)^0)
+
+ return lpeg.match(template_grammar, tmpl)
+end
+
return exports