forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
26
lib/leenkx2d/Sources/lnx2d/Path.hx
Normal file
26
lib/leenkx2d/Sources/lnx2d/Path.hx
Normal file
@ -0,0 +1,26 @@
|
||||
package lnx2d;
|
||||
|
||||
class Path {
|
||||
|
||||
public static function toRelative(path:String, cwd:String):String {
|
||||
path = haxe.io.Path.normalize(path);
|
||||
cwd = haxe.io.Path.normalize(cwd);
|
||||
|
||||
var ar:Array<String> = [];
|
||||
var ar1 = path.split("/");
|
||||
var ar2 = cwd.split("/");
|
||||
|
||||
var index = 0;
|
||||
while (ar1[index] == ar2[index]) index++;
|
||||
|
||||
for (i in 0...ar2.length - index) ar.push("..");
|
||||
|
||||
for (i in index...ar1.length) ar.push(ar1[i]);
|
||||
|
||||
return ar.join("/");
|
||||
}
|
||||
|
||||
public static function toAbsolute(path:String, cwd:String):String {
|
||||
return haxe.io.Path.normalize(cwd + "/" + path);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user