@todo handle strings that start or end with backtick

@param int $fragmentLevel
@return string
422684
protected function generateMarkdown( $fragmentLevel = 0 ) {
		$max = 0;
		preg_match_all('/`+/', $this->source, $result, PREG_PATTERN_ORDER);
		if( $result[0] ) {
			$max = max(array_map('\\strlen', $result[0]));
		}

		$quote = str_repeat('`', $max + 1);

		return "{$quote}{$this->source}{$quote}";
	}
829597
protected function _filterFragment($fragment)
    {
        if (! empty($fragment) && strpos($fragment, '#') === 0) {
            $fragment = substr($fragment, 1);
        }

        return $this->_filterQueryOrFragment($fragment);
    }
685533
protected function renderBody(int $indentLevel): string
    {
        $result = '';
        if (!empty($this->traits)) {
            $result .= $this->renderTraits($indentLevel + 1) . "\n\n";
        }

        if (!$this->constants->isEmpty()) {
            $result .= $this->constants->render($indentLevel + 1) . "\n\n";
        }

        if (!$this->properties->isEmpty()) {
            $result .= $this->properties->render($indentLevel + 1) . "\n\n";
        }

        if (!$this->methods->isEmpty()) {
            $result .= $this->methods->render($indentLevel + 1) . "\n\n";
        }

        return $result;
    }
1231882
public static function toString($numericLevel = self::NONE)
    {
        if (!is_numeric($numericLevel)) {
            throw new \InvalidArgumentException('The app type "' . $numericLevel . '" is not numeric.');
        }

        return static::nameOf($numericLevel);
    }
757031
public function render(int $indentLevel = 0): string
    {
        $result = '';

        if (!$this->docComment->isEmpty()) {
            $result .= $this->docComment->render($indentLevel) . "\n";
        }

        //Class header
        $header = "class {$this->getName()}";

        //Rendering extends
        if (!empty($this->extends)) {
            $header .= " extends {$this->extends}";
        }

        if (!empty($this->interfaces)) {
            $interfaces = join(", ", array_keys($this->interfaces));
            $header .= " implements {$interfaces}";
        }

        $result .= $this->addIndent($header, $indentLevel) . "\n";
        $result .= $this->addIndent("{", $indentLevel) . "\n";

        //Rendering class body
        $result .= $this->renderBody($indentLevel);

        $result = rtrim($result, "\n") . "\n";
        $result .= $this->addIndent("}", $indentLevel);

        return $result;
    }
258190
public function withFragment($fragment){
        if(!is_string($fragment)){
            throw new \InvalidArgumentException();
        }

        if("" !== $fragment && 1 !== preg_match(static::REGEX_FRAGMENT, $fragment)){
            throw new \InvalidArgumentException();
        }

        if($this->fragment === $fragment){
            return $this;
        }

        $clone              = clone $this;
        $clone->fragment    = $fragment;

        return $clone;
    }
51337
public static function getFirstSegment($segments)
    {
        if (is_array($segments)) {
            $vars = $segments;
        } else {
            $vars = self::segmentUrl($segments);
        }

        return current($vars);
    }
776225
public function GetThirdLevelDomain () {
		if ($this->domainParts === NULL) $this->initDomainSegments();
		return isset($this->domainParts[0]) ? $this->domainParts[0] : NULL;
	}
483248
public function NestedTitle($level = 2, $separator = " - ")
    {
        $item = $this;
        $parts = [];
        while ($item && $level > 0) {
            $parts[] = $item->Title;
            $item = $item->getParent();
            $level--;
        }
        return implode($separator, array_reverse($parts));
    }
674597
protected static function normalizeFragment(?string $fragment): ?string
    {
        if ($fragment === null) {
            return null;
        }

        if (!static::isValidFragment($fragment)) {
            $message = sprintf('Invalid URI fragment: %s', $fragment);
            throw new DomainException($message);
        }

        return static::encodeFragment(static::decode($fragment, static::UNRESERVED_SET));
    }
851701
private int getSectionLevel(SpanManager sm, Span sectionNameSpan)
	{
		int begin = sectionNameSpan.getStart();
		int end = sectionNameSpan.getEnd();
		int level = 0;

		try
		{
			while ((sm.charAt(begin + level) == '=')
					&& (sm.charAt(end - 1 - level) == '='))
			{
				level++;
			}
		}
		catch (StringIndexOutOfBoundsException e)
		{
			// there is no need to do anything!
			logger.debug("EXCEPTION IS OK: {}", e.getLocalizedMessage());
		}

		if (begin + level == end)
		{
			level = (level - 1) / 2;
		}

		return level;
	}
337929
public function getPartialURLFromSegment($segmentIdx) {

        $partialURL = "";

        for ($i = $segmentIdx; $i < sizeof($this->segments); $i++) {
            $partialURL .= (($i > $segmentIdx) ? "/" : "") . $this->segments [$i];
        }

        return $partialURL;
    }
1026373
public function formatUrl(string $url, string $delimiter = 'wp-admin', string $fragment = 'cms')
    {
        /*
         * If there is already a "cms" fragment in the URI,
         * just return the URL.
         */
        if (strrpos($url, $fragment) !== false) {
            return $url;
        }

        /*
         * The network admin URL is missing the "cms" fragment.
         * Let's add it.
         */
        $fragments = explode($delimiter, $url);

        /*
         * Insert in the middle the cms fragment appended with the wp-admin delimiter.
         */
        array_splice($fragments, 1, 0, "{$fragment}/{$delimiter}");

        /*
         * Build the URL by reducing (concatenating) all fragments.
         * This appends each fragment to the previous one.
         */
        $url = array_reduce($fragments, function ($carry, $item) {
            return $carry.=$item;
        });

        return $url;
    }
946648
static function createFromValidFragments(array $fragments) {
    $fqcnStr = '\\' . implode('\\', $fragments);
    $name = end($fragments);
    return new self($fqcnStr, $name);
  }
727613
public function segment($locale = null): ?string
    {
        if (is_null($locale)) {
            return $this->activeSegment();
        }

        return ($key = array_search($locale, $this->locales)) ? $key : null;
    }
1033296
private static String getFallbackString(String fallback) {
        int extStart = fallback.indexOf('@');
        if (extStart == -1) {
            extStart = fallback.length();
        }
        int last = fallback.lastIndexOf('_', extStart);
        if (last == -1) {
            last = 0;
        } else {
            // truncate empty segment
            while (last > 0) {
                if (fallback.charAt(last - 1) != '_') {
                    break;
                }
                last--;
            }
        }
        return fallback.substring(0, last) + fallback.substring(extStart);
    }
536396
protected function matchSegment($segments, $node, $level = 1)
    {
        $segment = isset($segments[$level - 1]) ? $segments[$level - 1] : false;

        if ($segment === false) {
            return false;
        }

        $segment = $segment ?: '/';

        foreach ($node as $regex => $child) {
            $this->count++;

            // Start with a '(' is a regex
            if ($regex[0] === '(') {
                preg_match(chr(1) . $regex . chr(1), $segment, $match);

                if (!$match) {
                    continue;
                }

                RouteHelper::getVariables($match, $this->vars);
            } else {
                // Otherwise it is a static string
                if ($regex != $segment) {
                    continue;
                }
            }

            $result = false;

            // Has child, iterate it.
            if ($child && is_array($child)) {
                $child = $this->matchSegment($segments, $child, $level + 1);
            }

            // If is string, means we get a route index, using this index to find Route from maps.
            if (is_string($child)) {
                $child = $this->routes[$this->routeMaps[$child]];
            }

            // Match this Route
            if ($child instanceof Route) {
                $result = $this->matchOptions($child, $this->method, $this->options);
            }

            // If match fail, continue find next element.
            if (!$result) {
                continue;
            }

            return $child;
        }

        return false;
    }