From 45c6c2c12f97f91d0550db2aa888f68f68116e9a Mon Sep 17 00:00:00 2001 From: DefaultGen Date: Mon, 3 Jun 2024 19:20:17 -0400 Subject: Small refactor --- lua/simple-denote/util.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lua/simple-denote/util.lua') diff --git a/lua/simple-denote/util.lua b/lua/simple-denote/util.lua index 643e2e7..7c01449 100644 --- a/lua/simple-denote/util.lua +++ b/lua/simple-denote/util.lua @@ -24,9 +24,19 @@ function M.splitstring(str, delim) return items end ---- Escape a string to use as a lua pattern -function M.escape(str) - return str:gsub("(%W)", "%%%1") +--- Trim whitespace on either end of string +function M.trim(str) + local from = str:match"^%s*()" + return from > #str and "" or str:match(".*%S", from) +end + +--- Remove special chars, make lowercase, spaces to dashes +function M.plain_format(str) + str = str:lower() + str = str:gsub("[^%w%s]","") + str = M.trim(str) + str = str:gsub("%s+","-") + return str end return M -- cgit v1.2.3