Pulls out relevent information on a given segment.

@param  string $segment The segment
@return array           ['segment' => (string), name' => (string), 'regex' => (string), 'optional' => (boolean)]
544653
protected function parseSegment($segment)
	{
		$optional = false;

		list($regex, $name) = \explode(":", $segment);

		if (\substr($name, -1) === "?")
		{
			$name = \substr($name, 0, -1);
			$optional = true;
		}

		if ($regex === "")
		{
			$regex = "[^\/]+";
		}

		$regex = "/(?P<{$name}>{$regex})";

		if ($optional)
		{
			$regex = "(?:{$regex})?";
		}

		return array(
			'segment' => $segment,
			'token' => "/".$segment,
			'name' => $name,
			'regex' => $regex,
			'optional' => $optional
		);
	}
67997
protected function buildSegments(array $segments)
    {
        $pattern  = "";
        $patterns = [];
        $wildcardTokens = array_keys($this->wildcards);
        $wildcardRegex  = $this->wildcards;

        foreach ($segments as $n => $segment) {
            if ($segment === "" && $n !== 0) {
                throw new BadRouteException(BadRouteException::EMPTY_OPTIONAL_PARTS);
            }

            $patterns[] = $pattern .= str_replace($wildcardTokens, $wildcardRegex, $segment);
        }

        return $patterns;
    }
595381
public function segment($segment)
    {
        $segments = $this->segments;

        return isset($segments[$segment - 1]) ? $segments[$segment - 1] : false;
    }
460922
public static function getPathSegments(array $exclude = array()): array
    {
        $exclude = array_merge($exclude, array(
            INDEX_FILE,
            CHAR_SPACE,
            ''
        ));
        
        $exclude[] = "";
        
        $requestUri = self::getServerVariable('REQUEST_URI', '');
        $requestUri = substr($requestUri, 0, (strpos($requestUri, "?") !== false) ? strpos($requestUri, "?") : strlen($requestUri));
        $requestUri = preg_replace("#/+#", "/", $requestUri);
        
        $pathInfo = explode(CHAR_SLASH, $requestUri);
        return array_values(array_diff(array_merge($pathInfo, $exclude), $exclude));
    }
494990
private function parseArguments($url)
	{
		preg_match_all('~{(n:|a:|an:|w:|\*:|\?:)?([a-zA-Z0-9_]+)}~', $url, $matches);

		if (isset($matches[2]) && !empty($matches[2])) {
			return $matches[2];
		}

		return [];
	}
457157
public function prepend($segment)
    {
        $segments = is_array($segment) ? $segment : func_get_args();

        $newPath = $this->path->copy();

        foreach (array_reverse($segments) as $segment) {
            $newPath->prepend($segment);
        }

        return $this->replicate(['path' => $newPath]);
    }
52989
public function parse(&$segments)
    {
        $vars = array();

        if (preg_match('/@\w+/', current($segments))) {
            $vars['oid'] = str_replace('@', '', array_shift($segments));
        }

        if (!empty($segments)) {
            $vars['term'] = array_pop($segments);
        }

        return $vars;
    }
167481
protected function _getSegmentValues()
    {
        return array(
            'customer_group_id' => array(self::XML_PATH_SEGMENT_CUSTOMER_GROUP, function () {
                return $this->_noSessionCall ? 0 : Mage::getSingleton('customer/session')->getCustomerGroupId();
            }),
            'store_id' => array(self::XML_PATH_SEGMENT_STORE, function () {
                return Mage::app()->getStore()->getId();
            }),
            'currency' => array(self::XML_PATH_SEGMENT_CURRENCY, function () {
                return Mage::app()->getStore()->getCurrentCurrencyCode();
            })
        );
    }
910173
public static function segmentIsOptional($segment)
        {
            $name = mb_substr($segment, 1);

            $optMarkerPos = mb_strpos($name, '?');

            if ($optMarkerPos === false) return false;

            $regexMarkerPos = mb_strpos($name, '|');

            if ($regexMarkerPos === false) return true;

            if ($optMarkerPos !== false && $regexMarkerPos !== false) return $optMarkerPos < $regexMarkerPos;

            return false;
        }
169794
public function parse($segment)
    {
        $generated = new PosGenerated();
        $source = new PosSource();
        $pos = new PosMap($generated, $source);
        try {
            $offsets = $this->encoder->decode($segment);
        } catch (VLQError $e) {
            throw new InvalidMappings('Invalid segment "'.$segment.'"', $e);
        }
        $count = count($offsets);
        if (!in_array($count, [1, 4, 5])) {
            throw new InvalidMappings('Invalid segment "'.$segment.'"');
        }
        $generated->line = $this->gLine;
        $this->gColumn += $offsets[0];
        $generated->column = $this->gColumn;
        if ($count >= 4) {
            $this->sFile += $offsets[1];
            $this->sLine += $offsets[2];
            $this->sColumn += $offsets[3];
            $source->fileIndex = $this->sFile;
            $source->line = $this->sLine;
            $source->column = $this->sColumn;
            if ($count === 5) {
                $this->sName += $offsets[4];
                $source->nameIndex = $this->sName;
            }
        }
        return $pos;
    }
73183
public static function getSegmentDefaultValue($segment)
        {
            $optMarkerPos = mb_strpos($segment, '?');

            if ($optMarkerPos === false) return false;

            $regexMarkerPos = mb_strpos($segment, '|');
            $value = false;

            if ($regexMarkerPos !== false) $value = mb_substr($segment, $optMarkerPos + 1, $regexMarkerPos-$optMarkerPos - 1);
            else $value = mb_substr($segment, $optMarkerPos + 1);

            return strlen($value) ? $value : false;
        }
417120
protected function getExtraConditions(array $segments)
    {
        $extra = [];

        $count = count($segments);

        for ($i = 0; $i < $count; $i += 2) {
            $extra[$segments[$i]] = $segments[$i + 1];
        }

        return $extra;
    }
460603
private function lookupRecursively(array $segments, \stdClass $context)
    {
        $segment = str_replace(['~0', '~1'], ['~', '/'], array_shift($segments));
        if (property_exists($context, $segment)) {
            if (!count($segments)) {
                return $context->$segment;
            }

            return $this->lookupRecursively($segments, $context->$segment);
        }

        return null;
    }
1151884
public static function join(...$segments)
    {
        $path = array();
        foreach ($segments as $segment) {
            $path = array_merge($path, (array) $segment);
        }

        $path = array_map(function ($segment) {
            return trim($segment, DIRECTORY_SEPARATOR);
        }, $path);

        $path = array_filter($path);

        $path = implode(DIRECTORY_SEPARATOR, $path);

        // First segment slash.
        if ((is_array($segments[0]) && strpos($segments[0][0], DIRECTORY_SEPARATOR) === 0)
            || strpos($segments[0], DIRECTORY_SEPARATOR) === 0
        ) {
            return DIRECTORY_SEPARATOR . $path;
        }
        return $path;
    }
802991
protected function getSegments($pattern)
	{
		$segments = array();
		$parts = \explode("/", ltrim($pattern, "/"));

		foreach ($parts as $segment)
		{
			if (\strpos($segment, ":") !== false)
			{
				$segments[] = $this->parseSegment($segment);
			}
		}

		return $segments;
	}
1049358
protected function parseSegments($string) {
        preg_match_all(
            '/^' .
            '((?P<protocol>.*):\/\/)?' .
            '(' .
                '(?P<username>.*?)' .
                '(:(?P<password>.*?)' .
            ')@)?' .
            '(?P<host>[^:\/\s]+)?' .
            '(:(?P<port>\d*))?' .
            '(?P<path>[^#\?]*)?' .
            '(\?(?P<query>[^#]*))?' .
            '(#(?P<fragment>.*))?' .
            '$/',
            $string,
            $segments
        );

        foreach ($segments as $key => $value) {
            if (is_numeric($key)) {
                unset($segments[$key]);
            } else {
                $segments[$key] = array_pop($value);
            }
        }

        $host = array_get($segments, 'host');

        if ($host && $host !== 'localhost' && stripos($host, '.') === false) {
            $segments['path'] = '/' . $host . array_get($segments, 'path');
            $segments['host'] = null;
        }

        return $segments;
    }
932360
public function segments()
	{
		$segments = explode('/', $this->path());

		return array_values(array_filter($segments, function ($v)
		{
			return $v != '';
		}));
	}