Fetch a URI Segment and add a trailing slash - helper function

@access private
@param integer
@param string
@param string
@return string
481354
function _slash_segment($n, $where='trailing', $which='segment') {
		$leading='/';
		$trailing='/';

		if ($where == 'trailing') {
			$leading='';
		} elseif ($where == 'leading') {
			$trailing='';
		}

		return $leading . $this->$which($n) . $trailing;
	}
911348
public static function getByIndex(Int $get = 1, Int $index = 1) : String
    {
        $segArr = self::segmentArray();

        if( $get == 0 )
        {
            $get = 1;
        }

        $get -= 1;
        $uri  = '';

        $countSegArr = count($segArr);

        if( $index < 0 )
        {
            $index = $countSegArr + $index + 1;
        }

        if( $index > 0 )
        {
            $index = $get + $index;
        }

        if( abs($index) > $countSegArr )
        {
            $index = $countSegArr;
        }

        for( $i = $get; $i < $index; $i++ )
        {
            $uri .= $segArr[$i].'/';
        }

        return rtrim($uri, '/');
    }
967625
public static function segmentizeUrl($url)
        {
            $url = self::normalizeUrl($url);
            $segments = explode('/', $url);

            $result = array();

            foreach ($segments as $segment) {
                if (strlen($segment)) $result[] = $segment;
            }

            return $result;
        }
273721
function site_url($uri = '')
	{
		if ($uri == '')
		{
			return $this->slash_item('base_url').$this->item('index_page');
		}

		if ($this->item('enable_query_strings') == FALSE)
		{
			$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
			return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
		}
		else
		{
			return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
		}
	}
195133
function urlEncodePath( $url )
    {
        // Raw encode the path part of the URL
        $urlComponents = parse_url( $url );
        $pathParts = explode( '/', $urlComponents['path'] );
        foreach ( $pathParts as $key => $pathPart )
        {
            $pathParts[$key] = rawurlencode( $pathPart );
        }
        $encodedPath = implode( '/', $pathParts );

        // Rebuild the URL again, like this: scheme://user:pass@host/path?query#fragment
        $encodedUrl = $urlComponents['scheme'] . '://';

        if ( isset( $urlComponents['user'] ) )
        {
            $encodedUrl .= $urlComponents['user'];
            if ( isset( $urlComponents['pass'] ) )
            {
                $encodedUrl .= ':' . $urlComponents['pass'];
            }
            $encodedUrl .= '@';
        }

        $encodedUrl .= $urlComponents['host'];
        if ( isset( $urlComponents['port'] ) )
        {
            $encodedUrl .= ':' . $urlComponents['port'];
        }
        $encodedUrl .= $encodedPath;

        if ( isset( $urlComponents['query'] ) )
        {
            $encodedUrl .= '?' . $urlComponents['query'];
        }

        if ( isset( $urlComponents['fragment'] ) )
        {
            $encodedUrl .= '#' . $urlComponents['fragment'];
        }

        return $encodedUrl;
    }
612394
public static function parseUri(string $uri){
        if(1 !== preg_match(static::REGEX_URI, $uri, $m)){
            return false;
        }

        $result = [
            "scheme"    => $m["scheme"] ?? "",
            "userinfo"  => $m["userinfo"] ?? "",
            "host"      => $m["host"] ?? "",
            "port"      => "" === $m["port"] ? null : (int)$m["port"],
            "path"      => $m["path"] ?? "",
            "query"     => $m["query"] ?? "",
            "fragment"  => $m["fragment"] ?? "",
        ];

        return $result;
    }
212905
function build_url( $parts = null )
	{
		if (is_string($parts))
		{
			if ($parts === '' || $parts === '//')
				return $this->uri->withScheme(null);								//	'//' . $this->uri->authority . $this->uri->getPathAndQuery();
			if ($parts[0] === '/')
				return $this->uri->getLeftPart(Uri::PARTIAL_AUTHORITY) . $parts;	//	(_::is_https() ? 'https://' : 'http://') . _::request('host') . $parts;
			if ($parts === 'https' || $parts === 'http')
				return $this->uri->withScheme($parts);								//	$parts . '://' . _::request('host') . _::request('uri');
			if ($parts[0] === '?')
				return $this->uri->getLeftPart(Uri::PARTIAL_PATH) . $parts;			//	(_::is_https() ? 'https://' : 'http://') . _::request('host') . _::request('path') . $parts;
			if (strpos($parts, '=') !== false)
				return $this->uri->getLeftPart(Uri::PARTIAL_PATH) . '?' . $parts;	//	(_::is_https() ? 'https://' : 'http://') . _::request('host') . _::request('path') . '?' . $parts;
			if ($parts[0] === '#')
				return $this->uri->withFragment($parts);							//	(_::is_https() ? 'https://' : 'http://') . _::request('host') . _::request('uri') . $parts;
			throw new \Exception("Invalid call to Request::build_url('{$parts}')");
		}
		return (string) (new Uri($parts));
/*
		return	(isset($parts['scheme']) ? (empty($parts['scheme']) ? '//' : $parts['scheme'] . '://') : ($this->uri->scheme ?? 'http') : 'http://')) .	// Can set `scheme` to NULL to generate a Protocol-Relative-URL!
				'//' . (empty($parts['host']) ? $this->uri->authority : $parts['host']) .
				(empty($parts['path']) ? _::request('path') : $parts['path']) .
				(isset($parts['query']) ? (empty($parts['query']) ? null : '?' . $parts['query']) : (empty($parts['path']) && _::request('query') ? '?' . _::request('query') : null)); // NO FRAGMENT! We can append it if we really need it!
*/
	}
644776
private function to_uri($string)
    {
        static $non_ascii;
        if (!$non_ascii)
        {
            $non_ascii = implode('', range("\x80", "\xFF"));
        }

        $position = 0;
        $strlen = strlen($string);
        while (($position += strcspn($string, $non_ascii, $position)) < $strlen)
        {
            $string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
            $position += 3;
            $strlen += 2;
        }

        return $string;
    }
1277064
private int look_for_slash_slash(char[] array, int cursor, int end) {
        while (cursor + 2 <= end) {
            int c = array[cursor++];
            if (c == '/') {
                c = array[cursor++];
                if (c == '/') {
                    return cursor;
                }
            }
        }
        return end;
    }
512329
public function getUrlPart($part_number)
	{
		// Split the url into an array by slashes
		$request_uri = array_filter(explode('/', $this->_request_uri), function($part) {
			return !empty($part);
		});

		return !empty($request_uri[$part_number]) ? $request_uri[$part_number] : null;
	}
88222
function toString()
    {
        $uri = '';

        if ($this->getScheme())
            $uri .= $this->getScheme() . ':'. '//';

        $uri .= $this->getAuthority();
        $uri .= parent::toString();

        if ($this->getHost() && (!$this->getQuery()->isEmpty() || $this->getFragment()))
            $uri .= '/';

        $replace = function ($match) { return rawurlencode($match[0]); };
        if (\Poirot\Std\cast($this->getQuery())->toArray()) {
            $regex   = '/(?:[^' .'a-zA-Z0-9_\-\.~' .'!\$&\'\(\)\*\+,;=' .'%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/';
            $uri .= "?" . preg_replace_callback($regex, $replace, $this->getQuery()->toString());
        }

        if ($this->getFragment()) {
            $regex   = '/(?:[^' .'a-zA-Z0-9_\-\.~' .'!\$&\'\(\)\*\+,;=' .'%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/';
            $uri .= "#" . preg_replace_callback($regex, $replace, $this->getFragment());
        }

        return $uri;
    }
1018174
function( string ){
            for( var i = 0; i < string.length; i++ ) string = string.replace( $this.slash.get() + $this.slash.get(), $this.slash.get());

            return string;
        }
370626
public function getUriSegment($index)
    {
        $segments = explode('/', $this->server->get('REQUEST_URI'));
        if (isset($segments[$index])) {
            return $segments[$index];
        }
        return false;
    }
154797
String getSuffix(URI uri) {

        String fragment = uri.getFragment();
        if (fragment != null) {
            fragment = "#" + fragment;
        } else {
            fragment = "";
        }

        String query = uri.getRawQuery();
        if (query != null) {
            query = "?" + query;
        } else {
            query = "";
        }
        return query.concat(fragment);
    }
868428
function getUri1() {
  const startPos = pos;
  let content = [];

  if (checkSC(pos)) content = content.concat(getSC());

  while (pos < tokens[startPos].uri_end) {
    if (checkInterpolation(pos)) content.push(getInterpolation());
    else if (checkUriRaw(pos)) content.push(getUriRaw());
    else break;
  }

  if (checkSC(pos)) content = content.concat(getSC());

  return content;
}
640883
function urlToUri(url) {
  let parts;

  if (!isUrl(url)) {
    throw new Error('Invalid url ' + url);
  }
  parts = urlParse.parse(url);

  return `${parts.hostname}${decodeURIComponent(parts.path)}`;
}
619802
function(url) {

         var parts = url.match(/^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/);
         var result = {
             url : parts[0],
             scheme : parts[1],
             host : parts[3],
             port : parts[4],
             path : parts[5],
             query : parts[6],
             fragment : parts[7],
         };
         result.root =
            result.scheme + '://' +
            result.host +
            (result.port ? ':' + result.port : '');

         return result;

    }