protected function Twig_Lexer::getOperatorRegex

1 call to Twig_Lexer::getOperatorRegex()
Twig_Lexer::__construct in drupal/core/vendor/twig/twig/lib/Twig/Lexer.php

File

drupal/core/vendor/twig/twig/lib/Twig/Lexer.php, line 369

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])) {
      $regex[] = preg_quote($operator, '/') . '(?=[\\s()])';
    }
    else {
      $regex[] = preg_quote($operator, '/');
    }
  }
  return '/' . implode('|', $regex) . '/A';
}