diff options
| author | DefaultGen <gravel.justness270@slmail.me> | 2024-06-03 19:20:17 -0400 |
|---|---|---|
| committer | DefaultGen <gravel.justness270@slmail.me> | 2024-06-03 19:20:17 -0400 |
| commit | 45c6c2c12f97f91d0550db2aa888f68f68116e9a (patch) | |
| tree | cd83b3c27d1ef48c8d742ffd6436b04013809997 /lua/simple-denote/util.lua | |
| parent | 17b947c5b2c0b67de7d2557f93793fcc284c6674 (diff) | |
| download | simple-denote.nvim-45c6c2c12f97f91d0550db2aa888f68f68116e9a.tar.gz | |
Small refactor
Diffstat (limited to 'lua/simple-denote/util.lua')
| -rw-r--r-- | lua/simple-denote/util.lua | 16 |
1 files changed, 13 insertions, 3 deletions
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 |
