Automattic\WooCommerce\EmailEditorVendor\Symfony\Component\CssSelector\Parser

Parser::parseSeries │ public static │ WC 1.0

Parses the arguments for ":nth-child()" and friends.

Метод класса: Parser{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$result = Parser::parseSeries( $tokens ): array;
$tokens(Token[]) (обязательный)
.

Код Parser::parseSeries() WC 11.3.0

public static function parseSeries(array $tokens): array
{
    foreach ($tokens as $token) {
        if ($token->isString()) {
            throw SyntaxErrorException::stringAsFunctionArgument();
        }
    }

    $joined = trim(implode('', array_map(function (Token $token) {
        return $token->getValue();
    }, $tokens)));

    $int = function ($string) {
        if (!is_numeric($string)) {
            throw SyntaxErrorException::stringAsFunctionArgument();
        }

        return (int) $string;
    };

    switch (true) {
        case 'odd' === $joined:
            return [2, 1];
        case 'even' === $joined:
            return [2, 0];
        case 'n' === $joined:
            return [1, 0];
        case !str_contains($joined, 'n'):
            return [0, $int($joined)];
    }

    $split = explode('n', $joined);
    $first = $split[0] ?? null;

    return [
        $first ? ('-' === $first || '+' === $first ? $int($first.'1') : $int($first)) : 1,
        isset($split[1]) && $split[1] ? $int($split[1]) : 0,
    ];
}