isOperator() public static method

Checks if the given string is an operator.
public static isOperator ( string $str ) : integer
$str string String to be checked.
return integer The appropriate flag for the operator.
Exemplo n.º 1
0
 public function testIsOperator()
 {
     $this->assertEquals(Token::FLAG_OPERATOR_ARITHMETIC, Context::isOperator('%'));
     $this->assertEquals(Token::FLAG_OPERATOR_LOGICAL, Context::isOperator('!'));
     $this->assertEquals(Token::FLAG_OPERATOR_LOGICAL, Context::isOperator('&&'));
     $this->assertEquals(Token::FLAG_OPERATOR_LOGICAL, Context::isOperator('<=>'));
     $this->assertEquals(Token::FLAG_OPERATOR_BITWISE, Context::isOperator('&'));
     $this->assertEquals(Token::FLAG_OPERATOR_ASSIGNMENT, Context::isOperator(':='));
     $this->assertEquals(Token::FLAG_OPERATOR_SQL, Context::isOperator(','));
     $this->assertEquals(Context::isOperator('a'), null);
 }
Exemplo n.º 2
0
 /**
  * Parses an operator.
  *
  * @return Token
  */
 public function parseOperator()
 {
     $token = '';
     /**
      * Value to be returned.
      * @var Token $ret
      */
     $ret = null;
     /**
      * The value of `$this->last` where `$token` ends in `$this->str`.
      * @var int $iEnd
      */
     $iEnd = $this->last;
     for ($j = 1; $j < Context::OPERATOR_MAX_LENGTH && $this->last < $this->len; ++$j, ++$this->last) {
         $token .= $this->str[$this->last];
         if ($flags = Context::isOperator($token)) {
             $ret = new Token($token, Token::TYPE_OPERATOR, $flags);
             $iEnd = $this->last;
         }
     }
     $this->last = $iEnd;
     return $ret;
 }