Removes from "?" position in string. If not found,
returns the original string.

@param string $path

@return string
762661
public static function removeQueryString($path)
    {
        if (false === $pos = strpos($path, '?')) {
            return $path;
        }

        $anchorPos = strpos($path, '#', $pos);

        $end = false === $anchorPos ? strlen($path) : $anchorPos;

        return substr($path, 0, $pos).substr($path, $end);
    }
1075945
protected function formatPath($path)
    {
        $path = trim($path, '/') . '/';
        if (strlen($path) > 1) {
            $path = '/' . $path;
        }

        return $path;
    }
119654
private function removeBasePath(string $path)
    {
        if (\strpos($path, $this->basePath) === 0) {
            $path = \substr($path, \strlen($this->basePath)) ?: '';
        }

        if ($path !== '' && $path[0] !== '/') {
            return '/' . $path;
        }

        return $path;
    }
536558
protected function removeDotSegments($path)
    {
        if ($path === null) {
            throw new \InvalidArgumentException('Path not set');
        }

        // §5.2.4.  Remove Dot Segments
        $input  = $path;
        $output = '';

        while ($input != '') {
            if (substr($input, 0, 3) == '../') {
                $input = (string) substr($input, 3);
            } elseif (substr($input, 0, 2) == './') {
                $input = (string) substr($input, 2);
            } elseif (substr($input, 0, 3) == '/./') {
                $input = substr($input, 2);
            } elseif ($input == '/.') {
                $input = '/';
            } elseif (substr($input, 0, 4) == '/../') {
                $input  = substr($input, 3);
                $pos    = strrpos($output, '/');
                if ($pos === false) {
                    $output = '';
                } else {
                    $output = substr($output, 0, $pos);
                }
            } elseif ($input == '/..') {
                $input  = '/';
                $pos    = strrpos($output, '/');
                if ($pos === false) {
                    $output = '';
                } else {
                    $output = substr($output, 0, $pos);
                }
            } elseif ($input == '.' || $input == '..') {
                $input = '';
            } else {
                $pos = strpos($input, '/', 1);
                if ($pos === false) {
                    $output    .= $input;
                    $input      = '';
                } else {
                    $output    .= substr($input, 0, $pos);
                    $input      = substr($input, $pos);
                }
            }
        }

        return $output;
    }
885525
public static function clean_up_path($path)
    {

        if (empty($path)) return '';
        if (strpos($path, '\\') !== false) {
            return str_replace("\\\\", "\\", $path);
        } else {
            return str_replace("//", "/", $path);
        }
    }
630301
private function filterPath(string $path): string
    {
        $path = \preg_replace_callback(
            '/(?:[^' . self::CHAR_UNRESERVED . ')(:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/u',
            [$this, 'urlEncodeChar'],
            $path
        );

        if ('' === $path) {
            // No path
            return $path;
        }

        if ($path[0] !== '/') {
            // Relative path
            return $path;
        }

        // Ensure only one leading slash, to prevent XSS attempts.
        return '/' . \ltrim($path, '/');
    }
1215751
protected static function removeDotSegments(string $path): string
    {
        $output = '';
        while ($path) {
            if ('..' == $path || '.' == $path) {
                break;
            }
            switch (true) {
                case ('./' == substr($path, 0, 2)):
                    $path = substr($path, 2);
                    break;
                case ('../' == substr($path, 0, 3)):
                    $path = substr($path, 3);
                    break;
                case ('/./' == substr($path, 0, 3)):
                    $path = substr($path, 2);
                    break;
                case ('/../' == substr($path, 0, 4)):
                    $path = '/'.substr($path, 4);
                    $pos = strrpos($output, '/', -1);
                    if ($pos !== false) {
                        $output = substr($output, 0, $pos);
                    }
                    break;
                case ('/..' == substr($path, 0, 3) && (in_array(substr($path, 3, 1), [false, '', '/'], true))):
                    $path = '/'.substr($path, 3);
                    $pos = strrpos($output, '/', -1);
                    if ($pos !== false) {
                        $output = substr($output, 0, $pos);
                    }
                    break;
                case ('/.' == substr($path, 0, 2) && (in_array(substr($path, 2, 1), [false, '', '/'], true))):
                    $path = '/'.substr($path, 2);
                    break;
                default:
                    $nextSlash = strpos($path, '/', 1);
                    if (false === $nextSlash) {
                        $segment = $path;
                    } else {
                        $segment = substr($path, 0, $nextSlash);
                    }
                    $output .= $segment;
                    $path = substr($path, strlen($segment));
                    break;
            }
        }

        return $output;
    }
1294254
public function stripScheme($path)
    {
        $scheme = preg_split('#://#', $path, 2);
        $scheme = end($scheme);

        return '/'.ltrim($scheme, '/');
    }
87538
static public function urlToPath($path)
    {
        $path = parse_url($path);
        return $path === null ? null : str_replace('/', DIRECTORY_SEPARATOR, $path['path']);
    }
1252372
private function filterPath(string $path): string
    {
        if ($path == '') {
            return $path;
        }

        $result = preg_replace_callback(
            '/(?:[^'.self::UNRESERVED.self::SUB_DELIMS.':@%~\/]+|%(?![A-Za-f0-9]{2}))/',
            function (array $match) {
                return rawurlencode($match[0]);
            },
            $path
        );

        if ($result[0] != '/') {
            return $result;
        }

        return '/'.ltrim($result, '/');
    }
661695
function removePathPrefix($path)
    {
        if (strpos($path, $this->getPathPrefix()) === false) {
            return basename($path);
        }

        return parent::removePathPrefix($path);
    }
959742
protected function removePathWhiteSpace(string $path): string
    {
        while (preg_match('#\p{C}+|^\./#u', $path)) {
            $path = preg_replace('#\p{C}+|^\./#u', '', $path);
        }

        return $path;
    }
798776
public static function fixPath($path)
    {
        // Detect which direction of slash is "wrong"
        switch (DIRECTORY_SEPARATOR) {
            case '\\':
                $wrongDirection = '/';
                break;

            case '/':
            default:
                $wrongDirection = '\\';
                break;
        }

        if (false !== stristr($path, $wrongDirection)) {
            $path = str_replace($wrongDirection, DIRECTORY_SEPARATOR, $path);

            // In case of mixed slashes we maybe need to cleanup
            if (stristr($path, '\\\\')) {
                $path = str_replace('\\\\', '\\', $path);
            } elseif (stristr($path, '//')) {
                $path = str_replace('//', '/', $path);
            }
        }

        // Return corrected path
        return $path;
    }
1059127
private function filterPath(?string $path): string
    {
        if (null === $path) {
            throw new SyntaxError('The path can not be null');
        }

        if ('' === $path || ',' === $path) {
            return 'text/plain;charset=us-ascii,';
        }

        if (1 === preg_match(self::REGEXP_DATAPATH, $path)) {
            $path = substr($path, 0, -1).'charset=us-ascii,';
        }

        if (1 === preg_match(self::REGEXP_NON_ASCII_PATTERN, $path) && false === strpos($path, ',')) {
            throw new SyntaxError(sprintf('The path `%s` is invalid according to RFC2937', $path));
        }

        return $path;
    }
347461
public static function normalizeFullPath($path)
    {
        $to = Folder::correctSlashFor($path);
        $from = ($to == '/' ? '\\' : '/');

        return str_replace($from, $to, $path);
    }
413313
protected function _filterPath($path)
    {
        $path = preg_replace_callback(
            '/(?:[^' . self::CHAR_UNRESERVED . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
            [$this, '_urlEncodeChar'],
            $path
        );

        if (empty($path)) {
            // No path
            return $path;
        }

        if ($path[0] !== '/') {
            // Relative path
            return $path;
        }

        // Ensure only one leading slash, to prevent XSS attempts.
        return '/' . ltrim($path, '/');
    }
158930
public static function trimPath($path) {
		$len = strlen($path);
		if ($path[$len - 1] == '\\' || $path[$len - 1] == '/') {
			$path = substr($path, 0, $len - 1);
		}

		return $path;
	}