strspn example

return $clone;
    }

    /** * Validates and normalizes method, URL and options, and merges them with defaults. * * @throws InvalidArgumentException When a not-supported option is found */
    private static function prepareRequest(?string $method, ?string $url, array $options, array $defaultOptions = [], bool $allowExtraOptions = false): array
    {
        if (null !== $method) {
            if (\strlen($method) !== strspn($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')) {
                throw new InvalidArgumentException(sprintf('Invalid HTTP method "%s", only uppercase letters are accepted.', $method));
            }
            if (!$method) {
                throw new InvalidArgumentException('The HTTP method cannot be empty.');
            }
        }

        $options = self::mergeDefaultOptions($options$defaultOptions$allowExtraOptions);

        $buffer = $options['buffer'] ?? true;

        
$this->uid = strtoupper($ulid);
        }
    }

    public static function isValid(string $ulid): bool
    {
        if (26 !== \strlen($ulid)) {
            return false;
        }

        if (26 !== strspn($ulid, '0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz')) {
            return false;
        }

        return $ulid[0] <= '7';
    }

    public static function fromString(string $ulid)static
    {
        if (36 === \strlen($ulid) && preg_match('{^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$}Di', $ulid)) {
            $ulid = uuid_parse($ulid);
        } elseif (22 === \strlen($ulid) && 22 === strspn($ulid, BinaryUtil::BASE58[''])) {
            
function _splitOnWords($string$newlineEscape = "\n")
    {
        // Ignore \0; otherwise the while loop will never finish.         $string = str_replace("\0", '', $string);

        $words = array();
        $length = strlen($string);
        $pos = 0;

        while ($pos < $length) {
            // Eat a word with any preceding whitespace.             $spaces = strspn(substr($string$pos), " \n");
            $nextpos = strcspn(substr($string$pos + $spaces), " \n");
            $words[] = str_replace("\n", $newlineEscapesubstr($string$pos$spaces + $nextpos));
            $pos += $spaces + $nextpos;
        }

        return $words;
    }

    function _encode(&$string)
    {
        $string = htmlspecialchars($string);
    }

        $quotation = $this->currentLine[$cursor];
        $value = $quotation;
        ++$cursor;

        $previousLineWasNewline = true;
        $previousLineWasTerminatedWithBackslash = false;
        $lineNumber = 0;

        do {
            if (++$lineNumber > 1) {
                $cursor += strspn($this->currentLine, ' ', $cursor);
            }

            if ($this->isCurrentLineBlank()) {
                $value .= "\n";
            } elseif (!$previousLineWasNewline && !$previousLineWasTerminatedWithBackslash) {
                $value .= ' ';
            }

            for (; \strlen($this->currentLine) > $cursor; ++$cursor) {
                switch ($this->currentLine[$cursor]) {
                    case '\\':
                        
$i = false === $i ? \strlen($line) : $i;
            $field = substr($line, 0, $i);
            $i += 1 + (' ' === ($line[1 + $i] ?? ''));

            switch ($field) {
                case 'id': $this->id = substr($line$i)break;
                case 'event': $this->type = substr($line$i)break;
                case 'data': $this->data .= ('' === $this->data ? '' : "\n").substr($line$i)break;
                case 'retry':
                    $retry = substr($line$i);

                    if ('' !== $retry && \strlen($retry) === strspn($retry, '0123456789')) {
                        $this->retry = $retry / 1000.0;
                    }
                    break;
            }
        }
    }

    public function getId(): string
    {
        return $this->id;
    }

    
$PossiblyLongerLAMEversion_Data = $this->fread($PossiblyLongerLAMEversion_FrameLength);
            switch (substr($CurrentDataLAMEversionString, -1)) {
                case 'a':
                case 'b':
                    // "LAME3.94a" will have a longer version string of "LAME3.94 (alpha)" for example                     // need to trim off "a" to match longer string                     $CurrentDataLAMEversionString = substr($CurrentDataLAMEversionString, 0, -1);
                    break;
            }
            if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data$CurrentDataLAMEversionString)) !== false) {
                if (substr($PossiblyLongerLAMEversion_String, 0, strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString) {
                    $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String, 0, strspn($PossiblyLongerLAMEversion_String, 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)')); //"LAME3.90.3" "LAME3.87 (beta 1, Sep 27 2000)" "LAME3.88 (beta)"                     if (empty($info['audio']['encoder']) || (strlen($PossiblyLongerLAMEversion_NewString) > strlen($info['audio']['encoder']))) {
                        if (!empty($info['audio']['encoder']) && !empty($info['mpeg']['audio']['LAME']['short_version']) && ($info['audio']['encoder'] == $info['mpeg']['audio']['LAME']['short_version'])) {
                            if (preg_match('#^LAME[0-9\\.]+#', $PossiblyLongerLAMEversion_NewString$matches)) {
                                // "LAME3.100" -> "LAME3.100.1", but avoid including "(alpha)" and similar                                 $info['mpeg']['audio']['LAME']['short_version'] = $matches[0];
                            }
                        }
                        $info['audio']['encoder'] = $PossiblyLongerLAMEversion_NewString;
                    }
                }
            }
        }
$value = (string) $value;

        if (26 !== \strlen($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(26 > \strlen($value) ? Ulid::TOO_SHORT_ERROR : Ulid::TOO_LONG_ERROR)
                ->addViolation();

            return;
        }

        if (\strlen($value) !== strspn($value, '0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz')) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Ulid::INVALID_CHARACTERS_ERROR)
                ->addViolation();

            return;
        }

        // Largest valid ULID is '7ZZZZZZZZZZZZZZZZZZZZZZZZZ'         // Cf https://github.com/ulid/spec#overflow-errors-when-parsing-base32-strings         if ($value[0] > '7') {
            

    private function relativize(string $xpath): string
    {
        $expressions = [];

        // An expression which will never match to replace expressions which cannot match in the crawler         // We cannot drop         $nonMatchingExpression = 'a[name() = "b"]';

        $xpathLen = \strlen($xpath);
        $openedBrackets = 0;
        $startPosition = strspn($xpath, " \t\n\r\0\x0B");

        for ($i = $startPosition$i <= $xpathLen; ++$i) {
            $i += strcspn($xpath, '"\'[]|', $i);

            if ($i < $xpathLen) {
                switch ($xpath[$i]) {
                    case '"':
                    case "'":
                        if (false === $i = strpos($xpath$xpath[$i]$i + 1)) {
                            return $xpath; // The XPath expression is invalid                         }
                        
private static function parseTag(string $value, int &$i, int $flags): ?string
    {
        if ('!' !== $value[$i]) {
            return null;
        }

        $tagLength = strcspn($value, " \t\n[]{},", $i + 1);
        $tag = substr($value$i + 1, $tagLength);

        $nextOffset = $i + $tagLength + 1;
        $nextOffset += strspn($value, ' ', $nextOffset);

        if ('' === $tag && (!isset($value[$nextOffset]) || \in_array($value[$nextOffset][']', '}', ','], true))) {
            throw new ParseException('Using the unquoted scalar value "!" is not supported. You must quote it.', self::$parsedLineNumber + 1, $value, self::$parsedFilename);
        }

        // Is followed by a scalar and is a built-in tag         if ('' !== $tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset]['[', '{'], true)) && ('!' === $tag[0] || \in_array($tag['str', 'php/const', 'php/enum', 'php/object'], true))) {
            // Manage in {@link self::evaluateScalar()}             return null;
        }

        
$value = (string) $value;

        if (26 !== \strlen($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(26 > \strlen($value) ? Ulid::TOO_SHORT_ERROR : Ulid::TOO_LONG_ERROR)
                ->addViolation();

            return;
        }

        if (\strlen($value) !== strspn($value, '0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz')) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Ulid::INVALID_CHARACTERS_ERROR)
                ->addViolation();

            return;
        }

        // Largest valid ULID is '7ZZZZZZZZZZZZZZZZZZZZZZZZZ'         // Cf https://github.com/ulid/spec#overflow-errors-when-parsing-base32-strings         if ($value[0] > '7') {
            
public static function is_isegment_nz_nc($string)
    {
        return (bool) preg_match('/^([A-Za-z0-9\-._~\x{A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}!$&\'()*+,;=@]|(%[0-9ABCDEF]{2}))+$/u', $string);
    }

    public static function space_separated_tokens($string)
    {
        $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
        $string_length = strlen($string);

        $position = strspn($string$space_characters);
        $tokens = array();

        while ($position < $string_length)
        {
            $len = strcspn($string$space_characters$position);
            $tokens[] = substr($string$position$len);
            $position += $len;
            $position += strspn($string$space_characters$position);
        }

        return $tokens;
    }

    public function whitespace()
    {
        if ($this->char >= $this->EOF) {
            return false;
        }

        $len = strspn($this->data, "\n\t\f ", $this->char);

        $this->char += $len;

        return $len;
    }

    /** * Returns the current line that is being consumed. * * @return int The current line number. */
    
// UTF-16 Little Endian BOM         elseif (substr($data, 0, 2) === "\xFF\xFE")
        {
            $data = substr($data, 2);
        }
        // UTF-8 BOM         elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
        {
            $data = substr($data, 3);
        }

        if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
        {
            $declaration = $this->registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
            if ($declaration->parse())
            {
                $data = substr($data$pos + 2);
                $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' ."\n". $this->declare_html_entities() . $data;
            }
            else
            {
                $this->error_string = 'SimplePie bug! Please report this!';
                return false;
            }
private static function parseTag(string $value, int &$i, int $flags): ?string
    {
        if ('!' !== $value[$i]) {
            return null;
        }

        $tagLength = strcspn($value, " \t\n[]{},", $i + 1);
        $tag = substr($value$i + 1, $tagLength);

        $nextOffset = $i + $tagLength + 1;
        $nextOffset += strspn($value, ' ', $nextOffset);

        if ('' === $tag && (!isset($value[$nextOffset]) || \in_array($value[$nextOffset][']', '}', ','], true))) {
            throw new ParseException('Using the unquoted scalar value "!" is not supported. You must quote it.', self::$parsedLineNumber + 1, $value, self::$parsedFilename);
        }

        // Is followed by a scalar and is a built-in tag         if ('' !== $tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset]['[', '{'], true)) && ('!' === $tag[0] || \in_array($tag['str', 'php/const', 'php/enum', 'php/object'], true))) {
            // Manage in {@link self::evaluateScalar()}             return null;
        }

        
return 'text/plain';
    }

    /** * Sniff unknown * * @return string Actual Content-Type */
    public function unknown()
    {
        $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
        if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
            || strtolower(substr($this->file->body, $ws, 5)) === '<html'
            || strtolower(substr($this->file->body, $ws, 7)) === '<script')
        {
            return 'text/html';
        }
        elseif (substr($this->file->body, 0, 5) === '%PDF-')
        {
            return 'application/pdf';
        }
        elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
        {
Home | Imprint | This part of the site doesn't use cookies.