Added utils.lua

File is not used extensively at current development; however, usage in
the future is to be considered.

Provide utility functions to aid built-in functions. Greater usage to be
made in future development.
This commit is contained in:
Ethan Smith-Coss 2023-01-08 22:29:33 +00:00
parent ceb8576281
commit 9472a7b969
Signed by: TheOnePath
GPG Key ID: 4E7D436CE1A0BAF1

40
utils.lua Normal file
View File

@ -0,0 +1,40 @@
local M = {}
M.iter_table_dump = function ( arr )
for k, v in pairs(arr) do
print("Table:", k, v)
end
end
local escape_chars = function ( text )
return string.gsub(text, "[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$|%.]", {
["\\"] = "\\\\",
["-"] = "\\-",
["("] = "\\(",
[")"] = "\\)",
["["] = "\\[",
["]"] = "\\]",
["{"] = "\\{",
["}"] = "\\}",
["?"] = "\\?",
["+"] = "\\+",
["*"] = "\\*",
["^"] = "\\^",
["$"] = "\\$",
["."] = "\\.",
})
end
-- :@dev: clean the text once it has been fetched from buffer
M.clean_buf = function ( text )
if not type(text) == "string" or text == nil then
print("[DEBUG - clean_buf] Given input is not of type string.")
return
end
return escape_chars( text )
:match( "^%s*(.-)%s*$" )
end
return M