SqlParser\Context::isComment PHP Method

isComment() public static method

Checks if the given string is the beginning of a whitespace.
public static isComment ( string $str ) : integer
$str string String to be checked.
return integer The appropriate flag for the comment type.
    public static function isComment($str)
    {
        $len = strlen($str);
        if ($str[0] === '#') {
            return Token::FLAG_COMMENT_BASH;
        } elseif ($len > 1 && $str[0] === '/' && $str[1] === '*') {
            return $len > 2 && $str[2] == '!' ? Token::FLAG_COMMENT_MYSQL_CMD : Token::FLAG_COMMENT_C;
        } elseif ($len > 1 && $str[0] === '*' && $str[1] === '/') {
            return Token::FLAG_COMMENT_C;
        } elseif ($len > 2 && $str[0] === '-' && $str[1] === '-' && static::isWhitespace($str[2])) {
            return Token::FLAG_COMMENT_SQL;
        }
        return null;
    }

Usage Example

 public function testIsComment()
 {
     $this->assertEquals(Token::FLAG_COMMENT_BASH, Context::isComment('#'));
     $this->assertEquals(Token::FLAG_COMMENT_C, Context::isComment('/*'));
     $this->assertEquals(Token::FLAG_COMMENT_C, Context::isComment('*/'));
     $this->assertEquals(Token::FLAG_COMMENT_SQL, Context::isComment('-- '));
     $this->assertEquals(Token::FLAG_COMMENT_SQL, Context::isComment("--\t"));
     $this->assertEquals(Token::FLAG_COMMENT_SQL, Context::isComment("--\n"));
     $this->assertEquals(Token::FLAG_COMMENT_BASH, Context::isComment('# a comment'));
     $this->assertEquals(Token::FLAG_COMMENT_C, Context::isComment('/*comment */'));
     $this->assertEquals(Token::FLAG_COMMENT_SQL, Context::isComment('-- my comment'));
     $this->assertEquals(null, Context::isComment('--not a comment'));
 }
All Usage Examples Of SqlParser\Context::isComment