classes/phing/system/io/UnixFileSystem.php
public function normalize($strPathname)
    {
        if (!strlen($strPathname)) {
            return '';
        }

        // Start normalising after any scheme that is present.
        // This prevents phar:///foo being normalised into phar:/foo
        // Use a regex as some paths may not by parsed by parse_url().
        if (preg_match('{^[a-z][a-z0-9+\-\.]+://}', $strPathname)) {
            $i = strpos($strPathname, '://') + 3;
        } else {
            $i = 0;
        }

        $n = strlen($strPathname);
        $prevChar = 0;
        for (; $i < $n; $i++) {
            $c = $strPathname{$i};
            if (($prevChar === '/') && ($c === '/')) {
                return self::normalizer($strPathname, $n, $i - 1);
            }
            $prevChar = $c;
        }
        if ($prevChar === '/') {
            return self::normalizer($strPathname, $n, $n - 1);
        }

        return $strPathname;
    }
public function normalize($strPathname)
    {
        if (!strlen($strPathname)) {
            return '';
        }

        // Start normalising after any scheme that is present.
        // This prevents phar:///foo being normalised into phar:/foo
        // Use a regex as some paths may not by parsed by parse_url().
        if (preg_match('{^[a-z][a-z0-9+\-\.]+://}', $strPathname)) {
            $i = strpos($strPathname, '://') + 3;
        } else {
            $i = 0;
        }

        $n = strlen($strPathname);
        $prevChar = 0;
        for (; $i < $n; $i++) {
            $c = $strPathname{$i};
            if (($prevChar === '/') && ($c === '/')) {
                return self::normalizer($strPathname, $n, $i - 1);
            }
            $prevChar = $c;
        }
        if ($prevChar === '/') {
            return self::normalizer($strPathname, $n, $n - 1);
        }

        return $strPathname;
    }
public function normalize ( $ strPathname ) { if ( ! strlen ( $ strPathname ) ) { return '' ; } // Start normalising after any scheme that is present. // This prevents phar:///foo being normalised into phar:/foo // Use a regex as some paths may not by parsed by parse_url(). if ( preg_match ( '{^[a-z][a-z0-9+\-\.]+://}' , $ strPathname ) ) { $ i = strpos ( $ strPathname , '://' ) + 3 ; } else { $ i = 0 ; } $ n = strlen ( $ strPathname ) ; $ prevChar = 0 ; for ( ; $ i < $ n ; $ i ++ ) { $ c = $ strPathname { $ i } ; if ( ( $ prevChar === '/' ) && ( $ c === '/' ) ) { return self :: normalizer ( $ strPathname , $ n , $ i - 1 ) ; } $ prevChar = $ c ; } if ( $ prevChar === '/' ) { return self :: normalizer ( $ strPathname , $ n , $ n - 1 ) ; } return $ strPathname ; }
A normal Unix pathname contains no duplicate slashes and does not end
with a slash.  It may be the empty string.

Check that the given pathname is normal.  If not, invoke the real
normalizer on the part of the pathname that requires normalization.
This way we iterate through the whole pathname string only once.

NOTE: this method no longer expands the tilde (~) character!

@param string $strPathname

@return string
A normal Unix pathname contains no duplicate slashes and does not end with a slash . It may be the empty string .