]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add Lua functions str_startswith and str_endswith 3476/head
authorAnton Yuzhaninov <citrin+git@citrin.ru>
Wed, 19 Aug 2020 15:58:31 +0000 (16:58 +0100)
committerAnton Yuzhaninov <citrin+git@citrin.ru>
Wed, 19 Aug 2020 15:58:31 +0000 (16:58 +0100)
lualib/lua_util.lua

index 5b0950419f4cb07081434671a6523552e4daaa28..6b42dbc5d9856c62895a42bb65f73e1a20da81e1 100644 (file)
@@ -96,6 +96,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