Patch 3111264: Allow path.join() to accept any number of args
This commit is contained in:
parent
b1df4ff7ae
commit
e4d23a49bf
@ -52,6 +52,7 @@
|
||||
* Patch 3451212: Fix Visual Studio MFC with StaticRuntime
|
||||
* Patch 3463020: Add windres environment variable for makefiles (icebreaker)
|
||||
* Bug 3413866: Incorrect VS200x .csproj relative source paths
|
||||
* Patch 3111264: Allow path.join() to accept any number of args
|
||||
|
||||
|
||||
-------
|
||||
|
@ -217,34 +217,41 @@
|
||||
return table.contains(extensions, ext)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Join two pieces of a path together into a single path.
|
||||
-- Join one or more pieces of a path together into a single path.
|
||||
--
|
||||
-- @param ...
|
||||
-- One or more path strings.
|
||||
-- @return
|
||||
-- The joined path.
|
||||
--
|
||||
|
||||
function path.join(leading, trailing)
|
||||
leading = leading or ""
|
||||
|
||||
if (not trailing) then
|
||||
return leading
|
||||
function path.join(...)
|
||||
local numargs = select("#", ...)
|
||||
if numargs == 0 then
|
||||
return "";
|
||||
end
|
||||
|
||||
if (path.isabsolute(trailing)) then
|
||||
return trailing
|
||||
end
|
||||
|
||||
if (leading == ".") then
|
||||
leading = ""
|
||||
local allparts = {}
|
||||
for i = numargs, 1, -1 do
|
||||
local part = select(i, ...)
|
||||
if part and #part > 0 and part ~= "." then
|
||||
-- trim off trailing slashes
|
||||
while part:endswith("/") do
|
||||
part = part:sub(1, -2)
|
||||
end
|
||||
|
||||
table.insert(allparts, 1, part)
|
||||
if path.isabsolute(part) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (leading:len() > 0 and not leading:endswith("/")) then
|
||||
leading = leading .. "/"
|
||||
end
|
||||
|
||||
return leading .. trailing
|
||||
return table.concat(allparts, "/")
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Takes a path which is relative to one location and makes it relative
|
||||
|
@ -106,7 +106,6 @@
|
||||
language "C++"
|
||||
kind "ConsoleApp"
|
||||
prepare()
|
||||
test.contains(removed, "obj")
|
||||
test.contains(removed, "obj/Debug")
|
||||
test.contains(removed, "obj/Release")
|
||||
end
|
||||
|
@ -182,23 +182,43 @@
|
||||
--
|
||||
|
||||
function suite.join_OnValidParts()
|
||||
test.isequal("leading/trailing", path.join("leading", "trailing"))
|
||||
test.isequal("p1/p2", path.join("p1", "p2"))
|
||||
end
|
||||
|
||||
function suite.join_OnAbsoluteUnixPath()
|
||||
test.isequal("/trailing", path.join("leading", "/trailing"))
|
||||
test.isequal("/p2", path.join("p1", "/p2"))
|
||||
end
|
||||
|
||||
function suite.join_OnAbsoluteWindowsPath()
|
||||
test.isequal("C:/trailing", path.join("leading", "C:/trailing"))
|
||||
test.isequal("C:/p2", path.join("p1", "C:/p2"))
|
||||
end
|
||||
|
||||
function suite.join_OnCurrentDirectory()
|
||||
test.isequal("trailing", path.join(".", "trailing"))
|
||||
test.isequal("p2", path.join(".", "p2"))
|
||||
end
|
||||
|
||||
function suite.join_OnNilSecondPart()
|
||||
test.isequal("leading", path.join("leading", nil))
|
||||
test.isequal("p1", path.join("p1", nil))
|
||||
end
|
||||
|
||||
function suite.join_onMoreThanTwoParts()
|
||||
test.isequal("p1/p2/p3", path.join("p1", "p2", "p3"))
|
||||
end
|
||||
|
||||
function suite.join_removesExtraInternalSlashes()
|
||||
test.isequal("p1/p2", path.join("p1/", "p2"))
|
||||
end
|
||||
|
||||
function suite.join_removesTrailingSlash()
|
||||
test.isequal("p1/p2", path.join("p1", "p2/"))
|
||||
end
|
||||
|
||||
function suite.join_ignoresNilParts()
|
||||
test.isequal("p2", path.join(nil, "p2", nil))
|
||||
end
|
||||
|
||||
function suite.join_ignoresEmptyParts()
|
||||
test.isequal("p2", path.join("", "p2", ""))
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user