Add path.normalize()

This commit is contained in:
Jason Perkins 2013-12-17 13:41:58 -05:00
parent 7669651db0
commit 0a596481a0

View File

@ -185,6 +185,29 @@
end
--
-- Remove any extraneous weirdness from a path, such as double slashes or
-- leading single dots.
--
-- @param p
-- The path to normalize.
-- @return
-- A path known weirdnesses removed.
--
function path.normalize(p)
-- trim off any leading "./" sequences
while p:startswith("./") do
p = p:sub(3)
end
-- remove any "//" sequences from path concatenation
p = p:gsub("//", "/")
return p
end
--
-- Takes a path which is relative to one location and makes it relative
-- to another location instead.