aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorAnton Yuzhaninov <citrin+git@citrin.ru>2020-08-19 16:58:31 +0100
committerAnton Yuzhaninov <citrin+git@citrin.ru>2020-08-19 16:58:31 +0100
commitef8f8ffba01b7599e170428ade2e208e2540906b (patch)
treee0b339d300053fbbc076bf572612cec8beb8614b /lualib
parent2549b7686d660e35ad46c0eb4acf736272f862a1 (diff)
downloadrspamd-ef8f8ffba01b7599e170428ade2e208e2540906b.tar.gz
rspamd-ef8f8ffba01b7599e170428ade2e208e2540906b.zip
[Minor] Add Lua functions str_startswith and str_endswith
Diffstat (limited to 'lualib')
-rw-r--r--lualib/lua_util.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 5b0950419..6b42dbc5d 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -97,6 +97,26 @@ exports.rspamd_str_trim = rspamd_str_trim
exports.str_trim = rspamd_str_trim
--[[[
+-- @function lua_util.str_startswith(text, prefix)
+-- @param {string} text
+-- @param {string} prefix
+-- @return {boolean} true if text starts with the specified prefix, false otherwise
+--]]
+exports.str_startswith = function(s, prefix)
+ return s:sub(1, prefix:len()) == prefix
+end
+
+--[[[
+-- @function lua_util.str_endswith(text, suffix)
+-- @param {string} text
+-- @param {string} suffix
+-- @return {boolean} true if text ends with the specified suffix, false otherwise
+--]]
+exports.str_endswith = function(s, suffix)
+ return s:sub(-suffix:len()) == suffix
+end
+
+--[[[
-- @function lua_util.round(number, decimalPlaces)
-- Round number to fixed number of decimal points
-- @param {number} number number to round