refact: file_extension

This commit is contained in:
Thomas Lambert
2023-04-29 00:24:24 +02:00
parent 4e2a433178
commit 0367fa6a66
2 changed files with 6 additions and 9 deletions

View File

@@ -892,14 +892,6 @@ function Pinfo:resolve_link(title, opts)
return self
end
-- local function endswith(s, ending)
-- return ending == "" or s:sub(-#ending) == ending
-- end
local function file_extension(fname)
return fname:match("^.+(%..+)$")
end
local function filter_filetypes(flist, ftypes)
local new_fl = {}
ftypes = ftypes or { M.Cfg.extension }
@@ -910,7 +902,7 @@ local function filter_filetypes(flist, ftypes)
end
for _, fn in pairs(flist) do
if ftypeok[file_extension(fn)] then
if ftypeok[fileutils.get_extension(fn)] then
table.insert(new_fl, fn)
end
end

View File

@@ -15,6 +15,11 @@ function M.file_exists(fname)
end
end
-- Returns the file extension
function M.get_extension(fname)
return fname:match("^.+(%..+)$")
end
-- Strips an extension from a file name, escaping "." properly, eg:
-- strip_extension("path/Filename.md", ".md") -> "path/Filename"
local function strip_extension(str, ext)