瀏覽代碼

Add Path.normalize

Lubos Lenco 4 年之前
父節點
當前提交
aa3da76303
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13 0
      Sources/arm/sys/Path.hx

+ 13 - 0
Sources/arm/sys/Path.hx

@@ -44,6 +44,19 @@ class Path {
 		return base;
 	}
 
+	public static function normalize(path: String): String {
+		var ar = path.split(Path.sep);
+		var i = 0;
+		while (i < ar.length) {
+			if (i > 0 && ar[i] == ".." && ar[i - 1] != "..") {
+				ar.splice(i - 1, 2);
+				i--;
+			}
+			else i++;
+		}
+		return ar.join(Path.sep);
+	}
+
 	public static function baseDir(path: String): String {
 		return path.substr(0, path.lastIndexOf(Path.sep) + 1);
 	}