public static boolean checkName()

in commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileName.java [86:113]


    public static boolean checkName(final String basePath, final String path, final NameScope scope) {
        if (scope == NameScope.FILE_SYSTEM) {
            // All good
            return true;
        }

        if (!path.startsWith(basePath)) {
            return false;
        }

        int baseLen = basePath.length();
        if (VFS.isUriStyle()) {
            // strip the trailing "/"
            baseLen--;
        }

        if (scope == NameScope.CHILD) {
            return path.length() != baseLen && (baseLen <= 1 || path.charAt(baseLen) == SEPARATOR_CHAR)
                    && path.indexOf(SEPARATOR_CHAR, baseLen + 1) == -1;
        }
        if (scope == NameScope.DESCENDENT) {
            return path.length() != baseLen && (baseLen <= 1 || path.charAt(baseLen) == SEPARATOR_CHAR);
        }
        if (scope == NameScope.DESCENDENT_OR_SELF) {
            return baseLen <= 1 || path.length() <= baseLen || path.charAt(baseLen) == SEPARATOR_CHAR;
        }
        throw new IllegalArgumentException();
    }