protected function Twig_Lexer::getOperatorRegex in Translation template extractor 6.3
Same name and namespace in other branches
- 7.3 vendor/Twig/Lexer.php \Twig_Lexer::getOperatorRegex()
- 7.2 vendor/Twig/Lexer.php \Twig_Lexer::getOperatorRegex()
1 call to Twig_Lexer::getOperatorRegex()
- Twig_Lexer::__construct in vendor/
Twig/ Lexer.php
File
- vendor/
Twig/ Lexer.php, line 365
Class
- Twig_Lexer
- Lexes a template string.
Code
protected function getOperatorRegex() {
$operators = array_merge(array(
'=',
), array_keys($this->env
->getUnaryOperators()), array_keys($this->env
->getBinaryOperators()));
$operators = array_combine($operators, array_map('strlen', $operators));
arsort($operators);
$regex = array();
foreach ($operators as $operator => $length) {
// an operator that ends with a character must be followed by
// a whitespace or a parenthesis
if (ctype_alpha($operator[$length - 1])) {
$r = preg_quote($operator, '/') . '(?=[\\s()])';
}
else {
$r = preg_quote($operator, '/');
}
// an operator with a space can be any amount of whitespaces
$r = preg_replace('/\\s+/', '\\s+', $r);
$regex[] = $r;
}
return '/' . implode('|', $regex) . '/A';
}