public static String patch(String path) {
String patchPath = path.trim();
// Move drive spec to the front of the path
if (patchPath.length() >= 3 &&
patchPath.charAt(0) == '/' &&
Character.isLetter(patchPath.charAt(1)) &&
patchPath.charAt(2) == ':') {
patchPath=patchPath.substring(1,3)+"/"+patchPath.substring(3);
}
// Eliminate consecutive slashes after the drive spec
if (patchPath.length() >= 2 &&
Character.isLetter(patchPath.charAt(0)) &&
patchPath.charAt(1) == ':') {
char[] ca = patchPath.replace('/', '\\').toCharArray();
char c;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ca.length; i++) {
if ((ca[i] != '\\') ||
(ca[i] == '\\' &&
i > 0 &&
ca[i - 1] != '\\')) {
if (i == 0 &&
Character.isLetter(ca[i]) &&
i < ca.length - 1 &&
ca[i + 1] == ':') {
c = Character.toUpperCase(ca[i]);
} else {
c = ca[i];
}
sb.append(c);
}
}
patchPath = sb.toString();
}
return patchPath;
}
|