isString() public static method

Checks if the given character is the beginning of a string.
public static isString ( string $str ) : integer
$str string String to be checked.
return integer The appropriate flag for the string type.
Example #1
0
 public function testIsString()
 {
     $this->assertEquals(Token::FLAG_STRING_SINGLE_QUOTES, Context::isString("'"));
     $this->assertEquals(Token::FLAG_STRING_DOUBLE_QUOTES, Context::isString('"'));
     $this->assertEquals(Token::FLAG_STRING_SINGLE_QUOTES, Context::isString("'foo bar'"));
     $this->assertEquals(Token::FLAG_STRING_DOUBLE_QUOTES, Context::isString('"foo bar"'));
     $this->assertEquals(Context::isString('foo bar'), null);
 }
Example #2
0
 /**
  * Parses a string.
  *
  * @param string $quote Additional starting symbol.
  *
  * @return Token
  */
 public function parseString($quote = '')
 {
     $token = $this->str[$this->last];
     if (!($flags = Context::isString($token)) && $token !== $quote) {
         return null;
     }
     $quote = $token;
     while (++$this->last < $this->len) {
         if ($this->last + 1 < $this->len && ($this->str[$this->last] === $quote && $this->str[$this->last + 1] === $quote || $this->str[$this->last] === '\\' && $quote !== '`')) {
             $token .= $this->str[$this->last] . $this->str[++$this->last];
         } else {
             if ($this->str[$this->last] === $quote) {
                 break;
             }
             $token .= $this->str[$this->last];
         }
     }
     if ($this->last >= $this->len || $this->str[$this->last] !== $quote) {
         $this->error(sprintf(__('Ending quote %1$s was expected.'), $quote), '', $this->last);
     } else {
         $token .= $this->str[$this->last];
     }
     return new Token($token, Token::TYPE_STRING, $flags);
 }