Merge branch 'pr2' of https://github.com/Blizzard/premake-core
This commit is contained in:
commit
0557e38efd
@ -13,6 +13,7 @@ int path_normalize(lua_State* L)
|
||||
char buffer[0x4000];
|
||||
char* src;
|
||||
char* dst;
|
||||
char* ptr;
|
||||
char last;
|
||||
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
@ -30,6 +31,24 @@ int path_normalize(lua_State* L)
|
||||
ch = '/';
|
||||
}
|
||||
|
||||
/* filter out .. */
|
||||
if (ch == '.' && last == '.') {
|
||||
ptr = dst - 3;
|
||||
while (ptr >= buffer) {
|
||||
if (*ptr != '/') {
|
||||
--ptr;
|
||||
}
|
||||
else {
|
||||
dst = ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ptr >= buffer) {
|
||||
++src;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* add to the result, filtering out duplicate slashes */
|
||||
if (ch != '/' || last != '/') {
|
||||
*(dst++) = ch;
|
||||
|
@ -364,3 +364,28 @@
|
||||
function suite.wildcards_escapeStarStar()
|
||||
test.isequal("Images/.*%.bmp", path.wildcards("Images/**.bmp"))
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- path.normalize tests
|
||||
--
|
||||
function suite.normalize_Test1()
|
||||
local p = path.normalize("d:/game/../test")
|
||||
test.isequal("d:/test", p)
|
||||
end
|
||||
|
||||
function suite.normalize_Test2()
|
||||
local p = path.normalize("d:/game/../../test")
|
||||
test.isequal("d:/../test", p)
|
||||
end
|
||||
|
||||
function suite.normalize_Test3()
|
||||
local p = path.normalize("../../test")
|
||||
test.isequal("../../test", p)
|
||||
end
|
||||
|
||||
function suite.normalize()
|
||||
test.isequal("d:/ProjectB/bin", path.normalize("d:/ProjectA/../ProjectB/bin"))
|
||||
test.isequal("/ProjectB/bin", path.normalize("/ProjectA/../ProjectB/bin"))
|
||||
end
|
Reference in New Issue
Block a user