FileDocCategorySizeDatePackage
URLUtil.javaAPI DocAndroid 1.5 API2016Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.util

URLUtil

public final class URLUtil extends Object

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringcanonicalizePath(java.lang.String path)
Canonicalize the path, i.e. remove ".." and "." occurences.

param
path the path to be canonicalized
return
the canonicalized path

        int dirIndex;

        while ((dirIndex = path.indexOf("/./")) >= 0) { //$NON-NLS-1$
            path = path.substring(0, dirIndex + 1)
                    + path.substring(dirIndex + 3);
        }

        if (path.endsWith("/.")) { //$NON-NLS-1$
            path = path.substring(0, path.length() - 1);
        }

        while ((dirIndex = path.indexOf("/../")) >= 0) { //$NON-NLS-1$
            if (dirIndex != 0) {
                path = path.substring(0, path
                        .lastIndexOf('/", dirIndex - 1))
                        + path.substring(dirIndex + 3);
            } else {
                path = path.substring(dirIndex + 3);
            }
        }

        if (path.endsWith("/..") && path.length() > 3) { //$NON-NLS-1$
            path = path.substring(0, path.lastIndexOf('/",
                    path.length() - 4) + 1);
        }
        return path;