Returns the index of the segment
@param string|\csslib\Segment $segment
@return \csslib\Segment|boolean
431835
private function getIndexOf($segment){
		if($segment instanceof Segment){
			foreach($this->segments as $index=>$other){
				if($other === $segment){
					return $index;
				}
			}
		}else{
			foreach($this->segments as $index=>$other){
				if($other->getName() === $segment){
					return $index;
				}
			}
		}
		return false;
	}
1137930
public function setSegment($segment)
    {
        if (array_key_exists($segment, $this->segments)) {
            return $this->segments[$segment];
        }
        // $reg = "#\[!--\sBEGIN\s$segment\s--\]<\/text:p>(.*?)<text:p\s.*>\[!--\sEND\s$segment\s--\]#sm";
        $reg = "#\[!--\sBEGIN\s$segment\s--\](.*?)\[!--\sEND\s$segment\s--\]#smU";
        if (preg_match($reg, html_entity_decode($this->contentXml), $m) == 0) {
            throw new OdfException("'$segment' segment not found in the document");
        }
        $this->segments[$segment] = new Segment($segment, $m[1], $this);
        return $this->segments[$segment];
    }
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;
        }
1291466
public function validate($segment)
    {
        //Slashes don't come in by segment so if a date has dashes, lets make them slashes
        $segment = str_replace('-', '/', $segment);

        try {
            $this->outputValue = new \DateTime($segment);
        } catch (\Exception $exception) {
            //Do nothing, this is a fail
            return false;
        }

        return ($this->outputValue->format('U') != 0);
    }
690908
public function segment($offset, $default = null)
	{
		if($this->offsetExists($offset))
			return $this->segments[$offset];

		return value($default);
	}
711165
public function getSegment($segment = 1)
    {
        $segment = (!is_null($segment)) ? $segment : 1;
        $uri = $this->router->getCurrentUri();
        $urlArray = array_filter(explode('/', $uri));
        $indexCount = array_search(Router::$indexPage, $urlArray);

        if ($indexCount == true) {
            $num = $indexCount + $segment;

            return isset($urlArray[$num]) ? $urlArray[$num] : null;
        }

        return isset($urlArray[$segment]) ? $urlArray[$segment] : null;
    }
370626
public function getUriSegment($index)
    {
        $segments = explode('/', $this->server->get('REQUEST_URI'));
        if (isset($segments[$index])) {
            return $segments[$index];
        }
        return false;
    }
274717
public function addSegments($segments)
    {
        if ( ! $segments instanceof Segments) {
            $segments = new Segments($segments);
        }

        $currentSegments = $this->segments->getParts();
        $addSegments = $segments->getParts();

        $uri = clone $this;
        $uri->segments = new Segments(array_merge($currentSegments, $addSegments));

        return $uri;
    }
1287741
public function parse(&$segments)
    {
        $query = array('view' => 'page');

        if (!empty($segments)) {
            $query['layout'] = str_replace('-', '_', implode('/', $segments));
        }

        return $query;
    }
780337
public static function root($segments = null): string
    {
        $path = __DIR__;
        for ($c1 = 0; $c1 < 4; $c1++) {
            $path = dirname($path);
        }
        $path = str_replace('\\', '/', $path);
        $path = self::addSegmentsToPath($path, $segments);
        return $path;
    }
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, '/');
    }
948493
public function offsetGet($offset)
    {
        return isset($this->pathSegments[$offset]) ? $this->pathSegments[$offset] : null;
    }
91657
public static function getUriSegment(int $segment)
    {
        $segments = self::getUriSegments();
        return isset($segments[$segment]) ? $segments[$segment] : null;
    }
153491
public function getSuggestedValuesForSegment($segmentName, $idSite)
    {
        if (empty(Config::getInstance()->General['enable_segment_suggested_values'])) {
            return array();
        }

        Piwik::checkUserHasViewAccess($idSite);

        $maxSuggestionsToReturn = 30;
        $segment = $this->findSegment($segmentName, $idSite);

        // if segment has suggested values callback then return result from it instead
        $suggestedValuesCallbackRequiresTable = false;
        if (isset($segment['suggestedValuesCallback'])) {
            $suggestedValuesCallbackRequiresTable = $this->doesSuggestedValuesCallbackNeedData(
                $segment['suggestedValuesCallback']);

            if (!$suggestedValuesCallbackRequiresTable) {
                return call_user_func($segment['suggestedValuesCallback'], $idSite, $maxSuggestionsToReturn);
            }
        }

        // if period=range is disabled, do not proceed
        if (!Period\Factory::isPeriodEnabledForAPI('range')) {
            return array();
        }

        if (!empty($segment['unionOfSegments'])) {
            $values = array();
            foreach ($segment['unionOfSegments'] as $unionSegmentName) {
                $unionSegment = $this->findSegment($unionSegmentName, $idSite);

                try {
                    $result = $this->getSuggestedValuesForSegmentName($idSite, $unionSegment, $maxSuggestionsToReturn);
                    if (!empty($result)) {
                        $values = array_merge($result, $values);
                    }
                } catch (\Exception $e) {
                    // we ignore if there was no data found for $unionSegmentName
                }
            }

            if (empty($values)) {
                throw new \Exception("There was no data to suggest for $segmentName");
            }

        } else {
            $values = $this->getSuggestedValuesForSegmentName($idSite, $segment, $maxSuggestionsToReturn);
        }

        $values = $this->getMostFrequentValues($values);
        $values = array_slice($values, 0, $maxSuggestionsToReturn);
        $values = array_map(array('Piwik\Common', 'unsanitizeInputValue'), $values);

        return $values;
    }
819549
protected function getIndexFromOffset($offset)
	{
		if ( ! is_numeric($offset) && is_int(+$offset)) {
			throw new \InvalidArgumentException(
				__METHOD__."() expects parameter one, offset, to be an integer"
			);	
		}
		
		return $offset < 0 ? count($this->segments) + $offset : $offset;
	}
229655
public static function totalSegments() : Int
    {
        $segmentEx     = array_diff(self::segmentArray(), ["", " "]);
        $totalSegments = count($segmentEx);

        return $totalSegments;
    }
287173
private function prepareSegment(string $name, string $segment): string
    {
        if (!empty($segment)) {
            return $this->filterSegment($segment);
        }

        if (!isset($this->constrains[$name])) {
            return self::DEFAULT_SEGMENT;
        }

        if (is_array($this->constrains[$name])) {
            $values = array_map([$this, 'filterSegment'], $this->constrains[$name]);

            return join('|', $values);
        }

        return $this->filterSegment((string)$this->constrains[$name]);
    }