aboutsummaryrefslogtreecommitdiff
path: root/lua/denote/util.lua
diff options
context:
space:
mode:
authorDefaultGen <gravel.justness270@slmail.me>2024-06-01 22:35:39 -0400
committerDefaultGen <gravel.justness270@slmail.me>2024-06-01 22:35:39 -0400
commitbde89bcfe9ceb6d312a02d3361fb817c304544f6 (patch)
tree104d9e2b83130001e373206ba9378bf07a0c0b13 /lua/denote/util.lua
parent22818fd95f438f83d32f6e1d482c6c2ef58772a0 (diff)
downloadsimple-denote.nvim-bde89bcfe9ceb6d312a02d3361fb817c304544f6.tar.gz
Initial commit
Diffstat (limited to 'lua/denote/util.lua')
-rw-r--r--lua/denote/util.lua41
1 files changed, 23 insertions, 18 deletions
diff --git a/lua/denote/util.lua b/lua/denote/util.lua
index bd237eb..643e2e7 100644
--- a/lua/denote/util.lua
+++ b/lua/denote/util.lua
@@ -1,27 +1,32 @@
local M = {}
+
function M.splitspace(str)
- local chunks = {}
- for substring in str:gmatch("%S+") do
- table.insert(chunks, #chunks, substring)
- end
- return chunks
+ local chunks = {}
+ for substring in str:gmatch("%S+") do
+ table.insert(chunks, #chunks, substring)
+ end
+ return chunks
end
function M.splitstring(str, delim)
- local items = {}
- local fulldelim = nil
- if delim == "." or delim == "-" then
- fulldelim = "%" .. delim
- else
- fulldelim = delim
- end
- print("fulldelim: ", fulldelim)
- str = str .. delim
- for w in str:gmatch("(.-)" .. fulldelim) do
- items[#items + 1] = w
- end
- return items
+ local items = {}
+ local fulldelim = nil
+ if delim == "." or delim == "-" then
+ fulldelim = "%" .. delim
+ else
+ fulldelim = delim
+ end
+ str = str .. delim
+ for w in str:gmatch("(.-)" .. fulldelim) do
+ items[#items + 1] = w
+ end
+ return items
+end
+
+--- Escape a string to use as a lua pattern
+function M.escape(str)
+ return str:gsub("(%W)", "%%%1")
end
return M