protected function Twig_Lexer::getOperatorRegex in Translation template extractor 7.2
Same name and namespace in other branches
- 6.3 vendor/Twig/Lexer.php \Twig_Lexer::getOperatorRegex()
- 7.3 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 360
Class
- Twig_Lexer
- Lexes a template string.
Code
protected function getOperatorRegex() {
$operators = array_merge(array(
'=',
), array(
'not',
'-',
'+',
), array(
'or',
'and',
'b-or',
'b-xor',
'b-and',
'==',
'!=',
'<',
'>',
'>=',
'<=',
'not in',
'in',
'matches',
'starts with',
'ends with',
'..',
'+',
'-',
'~',
'*',
'/',
'//',
'%',
'is',
'is not',
'**',
));
$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';
}