public static function Parser::parseSeries in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/css-selector/Parser/Parser.php \Symfony\Component\CssSelector\Parser\Parser::parseSeries()
Parses the arguments for ":nth-child()" and friends.
Parameters
Token[] $tokens:
Return value
array
Throws
3 calls to Parser::parseSeries()
- FunctionExtension::translateNthChild in vendor/
symfony/ css-selector/ XPath/ Extension/ FunctionExtension.php - ParserTest::testParseSeries in vendor/
symfony/ css-selector/ Tests/ Parser/ ParserTest.php - @dataProvider getParseSeriesTestData
- ParserTest::testParseSeriesException in vendor/
symfony/ css-selector/ Tests/ Parser/ ParserTest.php - @dataProvider getParseSeriesExceptionTestData
File
- vendor/
symfony/ css-selector/ Parser/ Parser.php, line 63
Class
- Parser
- CSS selector parser.
Namespace
Symfony\Component\CssSelector\ParserCode
public static function parseSeries(array $tokens) {
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 array(
2,
1,
);
case 'even' === $joined:
return array(
2,
0,
);
case 'n' === $joined:
return array(
1,
0,
);
case false === strpos($joined, 'n'):
return array(
0,
$int($joined),
);
}
$split = explode('n', $joined);
$first = isset($split[0]) ? $split[0] : null;
return array(
$first ? '-' === $first || '+' === $first ? $int($first . '1') : $int($first) : 1,
isset($split[1]) && $split[1] ? $int($split[1]) : 0,
);
}