You are here

protected function Twig_Lexer::getOperatorRegex in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Lexer.php \Twig_Lexer::getOperatorRegex()
1 call to Twig_Lexer::getOperatorRegex()
Twig_Lexer::__construct in vendor/twig/twig/lib/Twig/Lexer.php

File

vendor/twig/twig/lib/Twig/Lexer.php, line 367

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';
}