2 package org
.de
.metux
.util
;
5 import java
.io
.IOException
;
7 public class PathNormalize
9 public static String
normalize(String path
)
14 path
= StrReplace
.replace("//", "/",
15 StrReplace
.replace("/./", "/", path
));
17 if (path
.endsWith("/"))
18 return path
.substring(0,path
.length()-1);
23 // normalize and strip off sysroot
24 public static String
normalize_strip_sysroot(String path
, String sysroot
)
26 sysroot
= normalize(sysroot
);
27 path
= normalize(path
);
29 if (path
.startsWith(sysroot
))
30 return path
.substring(sysroot
.length());
35 public static String
normalize_add_sysroot(String path
, String sysroot
)
37 sysroot
= normalize(sysroot
);
38 path
= normalize(path
);
40 if (path
.startsWith("/") && (!path
.startsWith(sysroot
)))
41 return normalize(sysroot
+"/"+path
);
46 public static String
strip_cwd(String path
)
50 return strip_cwd(path
,new File(".").getCanonicalPath());
54 throw new RuntimeException("File() failed ",e
);
58 public static String
strip_cwd(String path
, String cwd
)
62 path
= normalize(path
);
65 System
.err
.println("==>strip_cwd: path=\""+path
+"\"");
66 System
.err
.println("==> cwd=\""+cwd
+"\"");
68 if ((pos
=path
.indexOf(cwd
))==0)
69 return normalize("./"+path
.substring(cwd
.length()));