private function convertRawStringToRegex(ParsedRoute $parsedRoute, string $rawString) : string
    {
        if (empty($rawString)) {
            return '#^.*$#';
        }

        $this->variableNames = [];
        $bracketDepth = 0;
        $this->cursor = 0;
        $rawStringLength = mb_strlen($rawString);
        $regex = '';

        while ($this->cursor < $rawStringLength) {
            $char = $rawString[$this->cursor];

            switch ($char) {
                case ':':
                    $regex .= $this->getVarRegex($parsedRoute, mb_substr($rawString, $this->cursor));
                    break;
                case '[':
                    $regex .= '(?:';
                    $bracketDepth++;
                    $this->cursor++;
                    break;
                case ']':
                    $regex .= ')?';
                    $bracketDepth--;
                    $this->cursor++;
                    break;
                default:
                    $regex .= preg_quote($char, '#');
                    $this->cursor++;
            }
        }

        if ($bracketDepth != 0) {
            throw new RouteException(
                sprintf('Route has %s brackets', $bracketDepth > 0 ? 'unclosed' : 'unopened')
            );
        }

        return sprintf('#^%s$#', $regex);
    }
private function convertRawStringToRegex(ParsedRoute $parsedRoute, string $rawString) : string
    {
        if (empty($rawString)) {
            return '#^.*$#';
        }

        $this->variableNames = [];
        $bracketDepth = 0;
        $this->cursor = 0;
        $rawStringLength = mb_strlen($rawString);
        $regex = '';

        while ($this->cursor < $rawStringLength) {
            $char = $rawString[$this->cursor];

            switch ($char) {
                case ':':
                    $regex .= $this->getVarRegex($parsedRoute, mb_substr($rawString, $this->cursor));
                    break;
                case '[':
                    $regex .= '(?:';
                    $bracketDepth++;
                    $this->cursor++;
                    break;
                case ']':
                    $regex .= ')?';
                    $bracketDepth--;
                    $this->cursor++;
                    break;
                default:
                    $regex .= preg_quote($char, '#');
                    $this->cursor++;
            }
        }

        if ($bracketDepth != 0) {
            throw new RouteException(
                sprintf('Route has %s brackets', $bracketDepth > 0 ? 'unclosed' : 'unopened')
            );
        }

        return sprintf('#^%s$#', $regex);
    }
private function convertRawStringToRegex ( ParsedRoute $ parsedRoute , string $ rawString ) : string { if ( empty ( $ rawString ) ) { return '#^.*$#' ; } $ this -> variableNames = [ ] ; $ bracketDepth = 0 ; $ this -> cursor = 0 ; $ rawStringLength = mb_strlen ( $ rawString ) ; $ regex = '' ; while ( $ this -> cursor < $ rawStringLength ) { $ char = $ rawString [ $ this -> cursor ] ; switch ( $ char ) { case ':' : $ regex .= $ this -> getVarRegex ( $ parsedRoute , mb_substr ( $ rawString , $ this -> cursor ) ) ; break ; case '[' : $ regex .= '(?:' ; $ bracketDepth ++ ; $ this -> cursor ++ ; break ; case ']' : $ regex .= ')?' ; $ bracketDepth -- ; $ this -> cursor ++ ; break ; default : $ regex .= preg_quote ( $ char , '#' ) ; $ this -> cursor ++ ; } } if ( $ bracketDepth != 0 ) { throw new RouteException ( sprintf ( 'Route has %s brackets' , $ bracketDepth > 0 ? 'unclosed' : 'unopened' ) ) ; } return sprintf ( '#^%s$#' , $ regex ) ; }
Converts a raw string with variables to a regex

@param ParsedRoute $parsedRoute The route whose string we're converting
@param string $rawString The raw string to convert
@return string The regex
@throws RouteException Thrown if the route variables are not correctly defined
Converts a raw string with variables to a regex