Add `common.is_absolute_path`

This commit is contained in:
Guldoman 2022-06-01 03:48:47 +02:00
parent 13d062479a
commit 9a428648a9
No known key found for this signature in database
GPG Key ID: EA928C8BDA1A8825
2 changed files with 6 additions and 1 deletions

View File

@ -385,6 +385,11 @@ function common.normalize_path(filename)
end
function common.is_absolute_path(path)
return path:sub(1, 1) == PATHSEP or path:match("^(%a):\\")
end
function common.path_belongs_to(filename, path)
return string.find(filename, path .. PATHSEP, 1, true) == 1
end

View File

@ -605,7 +605,7 @@ end
-- This function should get only filenames normalized using
-- common.normalize_path function.
function core.project_absolute_path(filename)
if filename:match('^%a:\\') or filename:find('/', 1, true) == 1 then
if common.is_absolute_path(filename) then
return common.normalize_path(filename)
elseif not core.project_dir then
local cwd = system.absolute_path(".")