diff options
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 |
