diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-03-23 18:25:06 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-03-23 18:25:06 +0000 |
commit | 2265ed4109cb4cee9ee1d5df0e9cf629923ce1cd (patch) | |
tree | 56eb2684b9244a47372f46fc9ad4efc8c6f34161 /lualib | |
parent | cc9369cdf97415e514c8f751e14788d0c90f073b (diff) | |
download | rspamd-2265ed4109cb4cee9ee1d5df0e9cf629923ce1cd.tar.gz rspamd-2265ed4109cb4cee9ee1d5df0e9cf629923ce1cd.zip |
[Minor] Add a simple function to strip Lua comments
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/lua_util.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index b4707c4bd..ea193a975 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -1532,6 +1532,30 @@ end exports.dns_timeout_augmentation = dns_timeout_augmentation +---[[[ +--- @function lua_util.strip_lua_comments(lua_code) +-- Strips single-line and multi-line comments from a given Lua code string and removes +-- any extra spaces or newlines. +-- +-- @param lua_code The Lua code string to strip comments from. +-- @return The resulting Lua code string with comments and extra spaces removed. +-- +---]]] +local function strip_lua_comments(lua_code) + -- Remove single-line comments + lua_code = lua_code:gsub("%-%-[^\r\n]*", "") + + -- Remove multi-line comments + lua_code = lua_code:gsub("%-%-%[%[.-%]%]", "") + + -- Remove extra spaces and newlines + lua_code = lua_code:gsub("%s+", " ") + + return lua_code +end + +exports.strip_lua_comments = strip_lua_comments + -- Defines symbols priorities for common usage in prefilters/postfilters exports.symbols_priorities = { top = 10, -- Symbols must be executed first (or last), such as settings |