public function match()

in prod/php/ElasticOTel/Util/WildcardMatcher.php [85:123]


    public function match(string $text): bool
    {
        if (!$this->startsWithWildcard && $this->literalParts === [] && $text !== '') {
            return false;
        }

        $allowAnyPrefix = $this->startsWithWildcard;
        $textPos = 0;
        $numberOfPartsToCheckInLoop = count($this->literalParts);
        if ($numberOfPartsToCheckInLoop > 0 && !$this->endsWithWildcard) {
            --$numberOfPartsToCheckInLoop;
        }
        for ($i = 0; $i < $numberOfPartsToCheckInLoop; ++$i) {
            $currentLiteralPart = $this->literalParts[$i];
            $literalPartMatchPos = self::findSubString($text, $currentLiteralPart, $textPos, $this->isCaseSensitive);
            if ($literalPartMatchPos === false) {
                return false;
            }
            if (!$allowAnyPrefix && $literalPartMatchPos !== $textPos) {
                return false;
            }
            $textPos += strlen($currentLiteralPart);
            $allowAnyPrefix = true;
        }
        if ($numberOfPartsToCheckInLoop < count($this->literalParts)) {
            $lastPart = $this->literalParts[count($this->literalParts) - 1];
            if (!$this->startsWithWildcard && count($this->literalParts) === 1) {
                if (!self::areStringsEqual($lastPart, $text, $this->isCaseSensitive)) {
                    return false;
                }
            } else {
                if (!TextUtil::isSuffixOf($lastPart, $text, $this->isCaseSensitive)) {
                    return false;
                }
            }
        }

        return true;
    }